Hello all,
I've a seemingly simple question, but it's kind of got me thinkin there might be a "proper" way to accomplish my goal.
My goal is a simple MySQL database schema install.
In PHPMyAdmin I export a database, any database.
I then save the file to the root directory of my project as database.sql.
In my PHP script I open the file and pass it to mysql_query();
I receive errors telling my that my SQL is wrong.
Is there a specific PHP standard function for preparing database from PHPMyAdmin to be used with mysql_query()?
Here's a code sample:
<?php
include("config.php"); // connect to mysql
$sql = file_get_contents("database.sql"); // file_get_contents, or use fopen...
if(mysql_query($sql)){
echo "Database was installed!";
}else{
echo "There was an error installing the database: ".mysql_error();
}
?>
MySQL error is something like:
There was an error installing the database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE IF NOT EXISTS `snippets` ( `id` int(255) NOT NULL AUTO_INCREMENT' at line 22.
I guess a work around will do the job, but I was hoping PHP had something specifically for handling this data. I assumed that PHPMyAdmin export data was raw MySQL code, if so, why would I be getting errors?
Thanks guys (and girls)