0

我正在尝试用表填充数据库(对此我很陌生)执行.php后我得到的消息是:成功创建表“用户”表“tempRes”成功创建表“empRec”成功创建但是第二个和第三个表没有出现在 phpMyAdmin 的数据库中。SHOW TABLES & SHOW TABLE STATUS 仅显示“用户”表。有谁知道为什么会这样?我该如何纠正?这是我的代码:

   <?php
   // connect to the MySQL server
   $conn = new mysqli('localhost', 'fiona', 'xxx', 'Org_db');

   // check connection
   if (mysqli_connect_errno()) {
    exit('Connect failed: '. mysqli_connect_error());
   }
   // Performs the $sql query on the server to create the table users

    $sql = "CREATE TABLE IF NOT EXISTS `users` (
    `id` INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
     `name` VARCHAR(25) NOT NULL,
     `pass` VARCHAR(18) NOT NULL,
     `email` VARCHAR(45),
     `reg_date` TIMESTAMP
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8"; 
    // performs query to check table successfully created or get error message
    if ($conn->query($sql) === TRUE) {
     echo '<br/>Table "users" successfully created<br/>';
     }
     else {
     echo 'Error: '. $conn->error;
     }
    // Performs the $sql query on the server to create the table temporary reservations
    "CREATE TABLE IF NOT EXISTS `tempRes` (
      `tr_id` INT NOT NULL AUTO_INCREMENT, 
      `aaid` INT NOT NULL,
      `cid` INT NOT NULL, 
      `date_res` DATE NOT NULL, 
      `rem` VARCHAR(5) NOT NULL,
       primary key ( `tr_id` )) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8"; 

   if ($conn->query($sql) === TRUE) {
    echo 'Table "tempRes" successfully created<br/>';
   }
   else {
   echo 'Error: '. $conn->error;
   }
   // Performs the $sql query on the server to create the table employee records
     "CREATE TABLE IF NOT EXISTS `empRec` (
     `eid`       INT NOT NULL auto_increment,
     `empPos`    VARCHAR( 20 ) NOT NULL,
     `tfn`       INT NOT NULL,
     `emp_DOB`   DATE NOT NULL,
     `eStart`    DATE NOT NULL,
    `super_co`  VARCHAR( 30 ),
    `s_mem_no`  INT NOT NULL,
    `icin`      INT NOT NULL,
    `epn`       INT NOT NULL,
      primary key ( emp_id )) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8";

    if ($conn->query($sql) === TRUE) {
    echo 'Table "empRec" successfully created<br/>';
    }
    else {
     echo 'Error: '. $conn->error;
    }
   ?>
4

1 回答 1

1

您没有将第二个和第三个创建语句存储在 $sql 变量中。这就是为什么不是?

在这两个语句的前面添加 $sql = infront

于 2013-10-13T00:39:58.803 回答