mit
Новичок
Восстановление дампа MySQL
Как заставить mysql выполнить все инструкции из файла? Весь форум перерыл, попробовал все что нашел, но инструкции не выполняются.
Вот код:
Как заставить mysql выполнить все инструкции из файла? Весь форум перерыл, попробовал все что нашел, но инструкции не выполняются.
Вот код:
Код:
<?php
/* Соединение, выбор БД */
$link = mysql_connect("localhost", "root", "")
or die("Could not connect");
print "Connected successfully";
mysql_select_db("000") or die("Could not select database");
function parse_mysql_dump($url, $ignoreerrors = false) {
$file_content = file($url);
//print_r($file_content);
$query = "";
foreach($file_content as $sql_line) {
$tsl = trim($sql_line);
if (($sql_line != "") && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != "#")) {
$query .= $sql_line;
if(preg_match("/;\s*$/", $sql_line)) {
$result = mysql_query($query);
if (!$result && !$ignoreerrors) die(mysql_error());
$query = "";
}
}
}
}
if(parse_mysql_dump("2.sql")) echo "YES!";
else echo "NO!";
?>