<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('allheight', $con);
$sql = 'CREATE TABLE Posts
(
PostID int NOT NULL AUTO_INCREMENT,
Title varchar(15),
Picture varchar(2000),
Description text,
Height text
)';
mysql_query($sql, $con);
mysql_close($con);
?>
这里的问题是代码似乎无法创建表“帖子”。
答案 0 :(得分:3)
如果您查找了MySQL错误消息,那就很明显了:
1075 - 表定义不正确;只能有一个自动列,必须将其定义为键
所以将SQL更改为
CREATE TABLE Posts (
PostID int NOT NULL AUTO_INCREMENT,
Title varchar(15),
Picture varchar(2000),
Description text,
Height text,
PRIMARY KEY(PostId)
)
答案 1 :(得分:1)
此sql查询产生以下错误:
表定义不正确;只能有一个自动列,必须将其定义为键。
将此添加到查询的末尾:
CREATE TABLE Posts
(
PostID int NOT NULL AUTO_INCREMENT,
Title varchar(15),
Picture varchar(2000),
Description text,
Height text,
KEY (PostID)
)