Thread: Syntax Error
View Single Post
  #2 (permalink)  
Old 05-15-08, 04:32 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
The reason for the error lies within this line:
PHP Code:

$sqls explode("\n"$schema); 

This lines thells php to split the content of $schema on each "\n" php finds in the string.

The query you posted is definietely a multiline query, therefore it will be split over several array-items ($sqls is an array). Basically you will be running queries like these:
SQL Code:
  1. DROP TABLE IF EXISTS `phpdesk_admin`
next query:
SQL Code:
  1. CREATE TABLE `phpdesk_admin` (
next query:
SQL Code:
  1. `id` int(255) NOT NULL DEFAULT '0',
and so on.

As you can see, only the first query is correctly formatted, and correct syntax, and will therefor be run. The others will rresult in an error right away as it's completely invalid syntax.

Instead of splitting on "\n" (newlines), you should be splitting per query.
I'm not 100% sure, but I thought you could use mysqli_query to execute several queries at the same time. That way you could simply pass on the data in the .sql file, and run it on your server.
Or..., and this is probably the best way, you could run the following query:
SQL Code:
  1. source 'schema/mysql.sql
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote