SET FOREIGN_KEY_CHECKS = 0 не работает Серверный компьютер

Мое веб-приложение позволяет получать резервные копии и устанавливать файл восстановления sql. Когда сценарий восстановления удаляет все таблицы, но некоторые таблицы не удаляются из-за наличия внешних ключей. Поэтому я добавил некоторый код выше файла restore.php, который будет успешно выполняться в локальный, но сервер не работает. сервер не выполняет SET FOREIGN_KEY_CHECKS = 0.

моя локальная машина php версия: 5.38
Версия php сервера: 5.46

Спасибо !!

вот файл restore.php

$remove_foreign_key = 'SET FOREIGN_KEY_CHECKS = 0';
$result = mysqli_query( $conn,$remove_foreign_key  );
if( $result ) {
}
else{
echo "Error\n";
}


if (! empty($_FILES)) {
// Validating SQL file type by extensions
if (! in_array(strtolower(pathinfo($_FILES["backup_file"]["name"], PATHINFO_EXTENSION)), array(
"sql"))) {
$response = array(
"type" => "error",
"message" => "Invalid File Type");
} else {
if (is_uploaded_file($_FILES["backup_file"]["tmp_name"])) {



move_uploaded_file($_FILES["backup_file"]["tmp_name"], $_FILES["backup_file"]["name"]);
$response = restoreMysqlDB($_FILES["backup_file"]["name"], $conn);
}
}
}

function restoreMysqlDB($filePath, $conn)
{
$sql = '';
$error = '';

if (file_exists($filePath)) {
$lines = file($filePath);

foreach ($lines as $line) {

// Ignoring comments from the SQL script
if (substr($line, 0, 2) == '--' || $line == '') {
continue;
}

$sql .= $line;

if (substr(trim($line), - 1, 1) == ';') {
$result = mysqli_query($conn, $sql);
if (! $result) {
$error .= mysqli_error($conn) . "\n";
}
$sql = '';
}
} // end foreach

if ($error) {
$response = array(
"type" => "error",
"message" => $error
);
} else {
$response = array(
"type" => "success",
"message" => "Database Restore Completed Successfully.");
}
unlink($filePath);
} // end if file exists

return $response;
}
?>

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector