If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the largest domain name community on the internet and continues to grow every day. There are over 105,000 domainers on DNForum doing everything from buying domains, selling domains, learning about domains and discussing domains. Take a minute and Register.
Register Today on DNForum IT'S FREE!I am offering 1000 DNF$ to anyone who can help me solve this!
I bought a 300 Mb database, 60K+ records, in the form of a large flattext .sql file, but when I came to import it, many of the records contain un-escaped quotes (') which messes up the SQL INSERT queries:
Obviously, it's not just a case of escaping every quote in the file, because the quotes between the record's fields are necessary:INSERT INTO `articles` VALUES ('','Planning Your Wedding Is Easy','<p>Planning a wedding is one of the most nerve wracking times in any person's life...','Marriage-Wedding','Active');
... so what do I do? You can't escape them by hand because there's 60,000+ records, so how do I get them into a database?INSERT INTO `articles` VALUES ('','Planning Your Wedding Is Easy','<p>Planning a wedding is one of the most nerve wracking times in any person\'s life...','Marriage-Wedding','Active');
★ Neil Hillman - Web Developer, Pixel Pusher...
If you have PHP5 & the file is writeable.. create a copy to test on, but try the following:That /should/ work.PHP Code:<?php
$file = 'sqldump.sql';
$sql = file_get_contents($file);
$sql = ereg_replace("'s","\'s ",$sql);
$sql = ereg_replace("'t","\'s.",$sql);
$sql = ereg_replace("'s","\'t ",$sql);
$sql = ereg_replace("'t","\'t.",$sql);
file_put_contents($file,$sql);
?>
edit--fixed a few typoes
Last edited by dotDan; 12-16-2005 at 10:23 PM.
Bookmarks