-3
$createPersonTable_SQL = "CREATE TABLE ".$db['database'].".Person ( ";
    $createPersonTable_SQL .= "ID INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , ";
    $createPersonTable_SQL .= "FirstName VARCHAR( 50 ) , ";
    $createPersonTable_SQL .= "LastName VARCHAR( 50 ) NOT NULL , ";
    $createPersonTable_SQL .= "Sex VARCHAR( 4 ) NOT NULL , ";
    $createPersonTable_SQL .= "Age INT( 3 ) NOT NULL , ";
    $createPersonTable_SQL .= "Job VARCHAR( 50 ) NOT NULL , ";
    $createPersonTable_SQL .= "Height float( 2) NOT NULL , ";
    $createPersonTable_SQL .= "Weight float( 2 ) NOT NULL , ";
    $createPersonTable_SQL .= "Hobby VARCHAR( 1000 ) NOT NULL , ";
    $createPersonTable_SQL .= "Salary FLOAT( 2 ) NOT NULL ";
    $createPersonTable_SQL .= ")";

For the first line, if I run the part of the php code like this, table is created successfully. But if I change the first line to "CREATE TABLE '".$db['database']."'.Person ( "; table is created unsuccessfully. Can anyone explain why one version works but the other one doesn't. I run the code using xampp. Thanks!

LF00
  • 27,015
  • 29
  • 156
  • 295
lul
  • 21
  • 1
  • 8

1 Answers1

1

The database name cannot be wrapped into single quotes in mysql. You can use backtick if you need to:

$createPersonTable_SQL = "CREATE TABLE `".$db['database']."`.Person ( ";
Zbynek Vyskovsky - kvr000
  • 18,186
  • 3
  • 35
  • 43