Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2012
    Posts
    17

    Unanswered: Strange CREATE TABLE Issue

    The following query works fine when I do it phpmyadmin.

    Code:
    DROP TABLE IF EXISTS tmp_price_compare;
    				CREATE TABLE IF NOT EXISTS tmp_price_compare (
    				supplier_reference varchar(32) DEFAULT NULL,
    				quantity int(10) NOT NULL DEFAULT '0',
    				price decimal(20,6) NOT NULL DEFAULT '0.000000',
    				wholesale_price decimal(20,6) NOT NULL DEFAULT '0.000000'
    			) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
    When I try to put it in my code though like so:

    Code:
    mysql_query("DROP TABLE IF EXISTS tmp_price_compare;
    				CREATE TABLE IF NOT EXISTS tmp_price_compare (
    				supplier_reference varchar(32) DEFAULT NULL,
    				quantity int(10) NOT NULL DEFAULT '0',
    				price decimal(20,6) NOT NULL DEFAULT '0.000000',
    				wholesale_price decimal(20,6) NOT NULL DEFAULT '0.000000'
    			) ENGINE=InnoDB  DEFAULT CHARSET=utf8;")
    				or die(mysql_error());
    it gives me the following error:

    Code:
    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 IF NOT EXISTS tmp_price_compare ( supplier_reference varchar(32' at line 2
    Any thoughts?

    Thanks,

    Ron

  2. #2
    Join Date
    Mar 2003
    Posts
    280
    Try one query for drop, and one query for create

  3. #3
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    The PHP function mysql_query is expecting a single query. This is two. If you used mysqli instead of mysql functions you could use mysqli_multi_query.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •