[SOLVED] problem with MySQL from PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tsr
Forum Newbie
Posts: 9
Joined: Tue Apr 19, 2005 11:21 am

[SOLVED] problem with MySQL from PHP

Post 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?
Last edited by tsr on Tue Feb 07, 2006 10:41 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql_query() does not support multiple commands. Separate the drop table from the create table (and lose the semicolon in the process)
tsr
Forum Newbie
Posts: 9
Joined: Tue Apr 19, 2005 11:21 am

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

tsr
Forum Newbie
Posts: 9
Joined: Tue Apr 19, 2005 11:21 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. ;)
Post Reply