Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.
Sedo.com

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

Status
Not open for further replies.

Mr.Domains

DNF Addict
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?
 

dotDan

Level 4
Legacy Platinum Member
Joined
Apr 22, 2003
Messages
192
Reaction score
0
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.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Members Online

Sedo - it.com Premiums

IT.com

Premium Members

MariaBuy

Our Mods' Businesses

UrlPick.com

*the exceptional businesses of our esteemed moderators

Top Bottom