Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$sql = "CREATE TABLE comments ( ID INT NOT NULL AUTO_INCREMENT, PosterName VARCHAR(32), Title VARCHAR(32), Content VARCHAR(500) )"; $con->query($sql);
没有错误,连接数据库成功。有谁知道为什么它不起作用?
您应该已经看到该语句的错误:
表定义不正确;只能有一个自动列,并且必须将其定义为键:
auto_increment列必须有一个UNIQUE索引,或者更一般地说是PRIMARY KEY:
auto_increment
UNIQUE
PRIMARY KEY
$sql = "CREATE TABLE comments ( ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, PosterName VARCHAR(32), Title VARCHAR(32), Content VARCHAR(500) )";