search

Home  >  Q&A  >  body text

创建数据表错误: 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
// Create connection
$conn = new mysqli("localhost", "uesename", "password","test");
// Detect connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Use sql to create a data table
$ 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 {                                                                                                                                                                                            Table MyGuests created successfully"; ?>

changruichangrui1745 days ago1830

reply all(1)I'll reply

  • 城乡结合部部长

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

    The statement to create the table, there cannot be a comma here at the end, it should be enough to remove it. This is SQL syntax, commas are required at the beginning and not at the end.

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

    reply
    1
  • Cancelreply