消息:已成功创建表,但只有第一个出现在数据库中

时间:2013-10-13 00:36:04

标签: php sql mysqli

我正在尝试使用表填充数据库(我是新手)我执行.php时得到的消息是: 表"用户"成功创建 表" tempRes"成功创建 表" empRec"成功创建 但是第二个和第三个表没有出现在phpMyAdmin的数据库中。 SHOW TABLES& SHOW TABLE STATUS仅显示" user"表。 有谁知道为什么会这样?我怎样才能纠正? 这是我的代码:

   <?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;
    }
   ?>

1 个答案:

答案 0 :(得分:1)

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

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