• Welcome to DNForum.com™ - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars
    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 oldest global domain name community on the internet and continues to grow every day. There are over 45,000 domainers on DNForum doing everything from buying domains, selling domains, using our free in-house built tools, learning about domains and discussing domains. Take a minute and Register.

Wanted: Service Importing MySQL db with un-escaped quotes?

Status
Not open for further replies.

Mr.Domains

DNF Addict
The Originals
Legacy Exclusive Member
Joined
Sep 29, 2004
Messages
1,417
Reaction score
29
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:
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');
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?
 
If you have PHP5 & the file is writeable.. create a copy to test on, but try the following:
PHP:
<?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);
?>

That /should/ work.


edit--fixed a few typoes
 
Status
Not open for further replies.
Back
Top Bottom