View Full Version : Reading Mysql Files with PHP

05-30-2004, 04:23 AM
Hello Everyone,

Okay I am trying to read a .sql file in php and run it into a query.

The .sql file is perfectly fine becuase I can put it into phpmyadmin and it works great. But when I pull it from the file it errors everytime. I just dont get it.

here is the code I am using:

//Insert defualt data into tables
error("Sorry but we could not open the mysql schema Insert file. Please make sure you have uploaded the file in the correct folder.");
error("Sorry but we had a problem creating the tables. Please make sure you have correct mysql information. Your host will provide you with this information." . mysql_error());

ANY help is very appreciated!!! :D

05-30-2004, 09:16 AM
Print and echo are your friends. Print the SQL to screen and check it for errors.

05-30-2004, 10:19 AM
You may well find that phpMyAdmin processes the SQL a tad differently than a normal call to mysql_query($sql). Certainly phpMyAdmin can explode any SQL to component parts and process each in turn - eg

TRUNCATE TABLE `first_table`;
TRUNCATE TABLE `second_table`;

works fine in phpMyAdmin though would not work within a call to mysql_query due to having two commands rather than one.

See if you can grab areas of the schema.sql and process each in turn - maybe just explode by ; (dunno whether that is good for inserts though)

Also check the comments are actual comments and that you have no hashs missing.

05-30-2004, 07:48 PM
Okay I will try to see if I can't explode it in some way. Thanks okkie.