Create table LIKE won't work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robbo

    Create table LIKE won't work

    Hi,

    PHP - I'm trying to create a MySQL table like an existing MySql table.

    My PHP code is

    $query = "CREATE TABLE '".$new_db."'.' ".$new_name ."' LIKE '".
    $old_db."'.'".$ old_name."'";
    echo mysql_error()." <br>";

    When I run in the browser I get -

    You have an error in your SQL syntax near
    ''forest_client _XXX000001'.'ac counts' LIKE
    'forest_client_ fds000003'.'acc ounts'' at line 1

    The $new_db, $old_db and $old_name all do exist

    I have tried removing the quote marks and have tried to do it in
    MyPHPAdmin all to no avail

    Any ideas gratefully received

  • Jerry Stuckle

    #2
    Re: Create table LIKE won't work

    Robbo wrote:
    Hi,
    >
    PHP - I'm trying to create a MySQL table like an existing MySql table.
    >
    My PHP code is
    >
    $query = "CREATE TABLE '".$new_db."'.' ".$new_name ."' LIKE '".
    $old_db."'.'".$ old_name."'";
    echo mysql_error()." <br>";
    >
    When I run in the browser I get -
    >
    You have an error in your SQL syntax near
    ''forest_client _XXX000001'.'ac counts' LIKE
    'forest_client_ fds000003'.'acc ounts'' at line 1
    >
    The $new_db, $old_db and $old_name all do exist
    >
    I have tried removing the quote marks and have tried to do it in
    MyPHPAdmin all to no avail
    >
    Any ideas gratefully received
    >
    Try a MySQL newsgroup - like comp.databases. mysql. This one's for PHP
    questions.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Michael Fesser

      #3
      Re: Create table LIKE won't work

      ..oO(Robbo)
      >PHP - I'm trying to create a MySQL table like an existing MySql table.
      >
      >My PHP code is
      >
      >$query = "CREATE TABLE '".$new_db."'.' ".$new_name ."' LIKE '".
      >$old_db."'.'". $old_name."'";
      >echo mysql_error()." <br>";
      >
      >When I run in the browser I get -
      >
      >You have an error in your SQL syntax near
      >''forest_clien t_XXX000001'.'a ccounts' LIKE
      >'forest_client _fds000003'.'ac counts'' at line 1
      Why don't you use the double-quotes in the way they are meant for?
      And drop the single quotes - table names are not quoted.

      $query = "CREATE TABLE $new_db.$new_na me LIKE $old_db.$old_na me";

      Micha

      Comment

      • Andy Jeffries

        #4
        Re: Create table LIKE won't work

        On Sat, 14 Jul 2007 21:27:46 +0200, Michael Fesser wrote:
        And drop the single quotes - table names are not quoted.
        Table names can be quoted, but you must use backticks; and they are only
        necessary when the table names contain spaces or other dubious characters.

        Cheers,


        Andy

        Comment

        • Michael Fesser

          #5
          Re: Create table LIKE won't work

          ..oO(Andy Jeffries)
          >On Sat, 14 Jul 2007 21:27:46 +0200, Michael Fesser wrote:
          >And drop the single quotes - table names are not quoted.
          >
          >Table names can be quoted, but you must use backticks;
          Depends on the DBMS and - in case of MySQL - on the mode it's running
          in. See Msg-Id <news:q5drm4-9se.ln1@ophelia .g5n.co.uk>.

          Micha

          Comment

          Working...