What I am trying to do is a instalation script (that executes an sql file) and that will create my database in MySql.
I did a search and I found anything... while it should be very requested, isn't it?
I found this function, that works great, but has a problem: all the sql request have to be in one single line.
Code: Select all
Create database etc;but
Code: Select all
create table test1{
..
}this is the function:
Code: Select all
parse_mysql_dump("database.sql","localhost","prueba","root","");
function parse_mysql_dump($url,$nowhost,$nowdatabase,$nowuser,$nowpass){
$link = mysql_connect($nowhost, $nowuser, $nowpass);
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db($nowdatabase, $link);
if (!$db_selected) {
die ('Error : ' . mysql_error());
}
$file_content = file($url);
foreach($file_content as $sql_line){
if(trim($sql_line) != "" && strpos($sql_line, "--") === false){
// echo $sql_line . '<br>';
// $sql_line2 = str_replace(array("\r", "\n" ), '', $sql_line);
echo $sql_line. '<br>';
mysql_query($sql_line, $link) or die ("Error in the request: ".$sql_line."<br>");
}
}
}
Morty