登录

创建数据表错误: 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 ')ENGINE=InnoDB DEFAULT CHARSET=utf8' at line 7

<?php
    // 创建连接
    $conn = new mysqli("localhost", "uesename", "password","test");
    // 检测连接
    if ($conn->connect_error) 
    {    
    die("连接失败: " . $conn->connect_error);
    } 
    // 使用 sql 创建数据表
    $sql = "CREATE TABLE new (
    id int(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
     title varchar(100) NOT NULL,
      author varchar(20) NOT NULL,
      content text NOT NULL,
      created_at datetime NOT NULL,
    )ENGINE=InnoDB DEFAULT CHARSET=utf8 ";
    if ($conn->query($sql) === TRUE) 
    {    
       echo "Table MyGuests created successfully";
    } else {    
       echo "创建数据表错误: " . $conn->error;
    }
    $conn->close(); 
?>

# PHP
changrui changrui 1522 天前 1486 次浏览

全部回复(1) 我要回复

  • 城乡结合部部长

    城乡结合部部长2020-02-19 12:36:31

    创建表格的语句,最后这里不能有逗号,去掉应该就可以了。这个是sql语法,前面都需要逗号,最后不需要。

    created_at datetime NOT NULL
        )ENGINE=InnoDB DEFAULT CHARSET=utf8 ";

    回复
    1
  • 取消 回复 发送