Comments on: How to Restore MySQL Database from SQL File using PHP https://www.codexworld.com/restore-import-mysql-database-sql-file-using-php/ Web & Mobile App Development Company Mon, 03 Apr 2023 15:26:42 +0000 hourly 1 By: David Cropley https://www.codexworld.com/restore-import-mysql-database-sql-file-using-php/comment-page-1/#comment-232221 Mon, 03 Apr 2023 15:26:42 +0000 https://www.codexworld.com/?p=3083#comment-232221 You may want to drop the database if it already exists first or you will get errors. So I found adding this before the main loop helped…
// Start fresh by dropping db first
$dropDB = ‘DROP DATABASE IF EXISTS `’ . $dbName . ‘`;’;
if (!$db->query($dropDB)) {
$error .= ‘Error performing query “‘ . $dropDB . ‘“: ‘ . $db->error . ”;
}

]]>