How correctly run sql file for insert in MySQL?
Try use PDO:
$mysql_host = "localhost";
$mysql_database = "planets_test";
$mysql_user = "root";
$mysql_password = "";
# MySQL with PDO_MYSQL
$dbh= new PDO("mysql:host=$mysql_host;dbname=$mysql_database", $mysql_user, $mysql_password);
$query = file_get_contents("planets_db.sql");
$stmt = $dbh->prepare($query);
$stmt->execute();
Where planets_db.sql” is script generated PHPmyAdmin?
Script not return error, but table not created.
2
Answers
Since this is a script you can execute SQL with the following code:
If there is an error it should tell you what went wrong.
I checked your code in my PC. Nothing found any error. Please check your SQL file in the same directory or is it correct SQL file.