I have a .sql file and want to replace the already existing database by clicking a button. Everything works fine. Except the create query. Is there any query or command to import whole databases?
$filename = 'file.sql';
// MySQL host
$mysql_host = 'localhost';
// MySQL username
$mysql_username = 'user';
// MySQL password
$mysql_password = 'pw';
// Database name
$mysql_database = 'dbName';
// Connect to MySQL server
mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());
// Select database
mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());
$drop_db = "DROP DATABASE dbName";
mysql_query($drop_db) or die ("error");
$create_db = "";