Page 1 of 1

[SOLVED] problem with MySQL from PHP

Posted: Tue Feb 07, 2006 10:06 am
by tsr
Hi,

I have this (for me bizarre) problem. The following code:

Code: Select all

$link = mysql_connect($config['db_host'], $config['db_user'], $config['db_pass']) or die(mysql_error());
mysql_select_db($config['db_db'], $link) or die(mysql_error);

$result = mysql_query("
  DROP TABLE IF EXISTS `context`;

  CREATE TABLE `context` (
    `contextId` int(10) unsigned NOT NULL auto_increment,
    `name` char(50) NOT NULL default '',
    `description` char(100) NOT NULL default '',
    PRIMARY KEY  (`contextId`)
  ) ENGINE=MyISAM;
") or die(mysql_error());
Produces the following error:
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 `context` ( `contextId` int(10) unsigned NOT
But if I use the exact same sql-statements in a MySql-client I don't get any errors.

Please also note that the connection is working properly, so it is not that that's messing up my code.

Any clues?

Posted: Tue Feb 07, 2006 10:10 am
by feyd
mysql_query() does not support multiple commands. Separate the drop table from the create table (and lose the semicolon in the process)

Posted: Tue Feb 07, 2006 10:28 am
by tsr
thanks, so then I'll need to make/find a functionthat parses a sqldump an extracts every query, one by one, any tips?

Posted: Tue Feb 07, 2006 10:33 am
by feyd

Posted: Tue Feb 07, 2006 10:40 am
by tsr
You're evil :-)

Thanks alot, u just saved me a bunch of work, is that code out in the wild, or just on thees forums?

/tsr

Posted: Tue Feb 07, 2006 10:58 am
by feyd
If it's on the boards, it's open to all, most often. This is an open source server, and we will share anything we can. All code I post is open to anyone, otherwise I wouldn't post it. ;)