I have mysql dump file. How I can import this file into mysql using php?
I you want to use PHP, you can easily use the file()
function, which reads a file into an array line by line.
You could try something like that:
mysql_connect(BD_HOST, DB_USER, BD_PASS) or die("Error connecting to MySQL server: ".mysql_error());
mysql_select_db(DB_NAME);
$all_lines = file("mysql_dump.sql", FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);
foreach($all_lines as $query) {
if(substr($query, 0, 2) == "--") {
continue;
}
mysql_query($query) or die("Error executing query
"$query\"
".mysql_error());
}