Page 1 of 1

Inserting an SQL file into MySQL Database...

Posted: Sun Nov 19, 2006 10:12 pm
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 = "";
		}
	}

Posted: Mon Nov 20, 2006 2:35 pm
by feyd
Look through raghavan20's posts in regex. I'm pretty sure I helped him build a script similar to mysqlimport.

Posted: Mon Nov 20, 2006 10:40 pm
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...