Might be a beginner question...
Solved:see bottom of post for more info.
I have a .sql file that has 3 commands in it.
2 "Create Tables table' followed by a "Insert Into table"
Each command is terminated with a ;
If I copy the text directly into MySQL. no problems.
I'm trying to get a php file to run the information in the page.
Below the cut is what I tried, what happened, and what I realized:
I tried:
Is there a php command: Run_sql_in_file($filepath) ... or
Is there a way to split my .sql string that I'm getting from file_get_contents() into an array split by the semicolon character?
If not obvious I am quite new to PHP and pretty much self teaching as I go.
Thanks!
SOLVED:
I found the explode() command.
zimzat posted at about the same time.
I'm on the way out, but will post the final function I generated later if people are interested.
I have a .sql file that has 3 commands in it.
2 "Create Tables table' followed by a "Insert Into table"
Each command is terminated with a ;
If I copy the text directly into MySQL. no problems.
I'm trying to get a php file to run the information in the page.
Below the cut is what I tried, what happened, and what I realized:
I tried:
echo "Creating tables and data for <b>$sql_file_name</b>...";
$str = file_get_contents($filePath . $sql_file_name);
if (mysql_query($str)) {
echo " Done.<br />\n";
} else {
echo mysql_errno() . ": Error on query for sqlfile <b>$sql_file_name</b>: " . mysql_error() . "<br />\n";
die;
}The runtime came back with1064: Error on querry for sqlfile address.sql:My guess is that since PHP queries are submitted without a semi-colon that this tripped up the system. So my question:
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 `Address_Type`
( `AddType_UID` int(50) NOT NULL auto_increment' at line 15
Is there a php command: Run_sql_in_file($filepath) ... or
Is there a way to split my .sql string that I'm getting from file_get_contents() into an array split by the semicolon character?
If not obvious I am quite new to PHP and pretty much self teaching as I go.
Thanks!
SOLVED:
I found the explode() command.
I'm on the way out, but will post the final function I generated later if people are interested.
