Here is a function that would parse mysql dump and execute it. function parse_mysql_dump($url,$nowhost,$nowdatabase,$nowuser,$nowpass){ $link1 = mysql_connect($nowhost, $nowuser, $nowpass); if (!$link1) { die('Not connected : ' . mysql_error()); } // make foo the current db $db_selected = mysql_select_db($nowdatabase, $link1); if (!$db_selected) { die ('Can't use foo : ' .mysql_error()); } $content = file_get_contents($url); // Processing the SQL file content $file_content = explode("n",$content); $query = ""; foreach($file_content as $sql_line){ if(trim($sql_line) != "" && strpos($sql_line, "--") === false){ $query .= $sql_line; // Checking whether the line is a valid statement if(preg_match("/(.*);/", $sql_line)) { $query = substr($query, 0, strlen($query)-1); //Executing the parsed string, returns the error code in failure $result = mysql_query($query)or die(mysql_error().$query); $query = ""; } } } }
|
My Blog Title
|