Inserting an SQL file into MySQL Database...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Inserting an SQL file into MySQL Database...

Post by Mr Tech »

I've got this script that inserts the contents of an SQL file into a MySQL Database. However, it is messing up my HTML Editites because it replaces ; with nothing... Does anyone have a script that works better or can fix this script?

Code: Select all

$dump = @file("update.sql");
	$count = count($dump);
	
	for ($i=0 ;$i<$count ;$i++) {	
		if (!trim($dump[$i])) continue;
		if (ereg("^#",$dump[$i])) continue;
		$content .= str_replace(";","",$dump[$i]);
	
		if (ereg(";$",trim($dump[$i]))) {
		mysql_query($content);
		$content = "";
		}
	}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Look through raghavan20's posts in regex. I'm pretty sure I helped him build a script similar to mysqlimport.
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

I can't find it...

Is there a better way to insert multiple tables and data into a MySQL Database using php rather than reading from an SQL file?

phpMyAdmin's import feature works well... I just can't find it in their code and I can't find much in Google...
Post Reply