我正在为我的SQLite数据库创建AUTOINCREMENT函数,但每当我输入AUTOINCREMENT函数时,我都会收到错误' SYNTAX'错误,我做错了什么?
<?php
$db = sqlite_open("user_indormation.db");
@sqlite_query($db, "DROP TABLE user_info");
sqlite_query($db,
"CREATE TABLE user_info (
ID INTEGER(100) AUTOINCREMENT,
FirstName VARCHAR2(10) NOT NULL,
SurName VARCHAR2(10) NOT NULL,
UserName VARCHAR2(10) NOT NULL,
CONSTRAINT USER_PRIMARY_KEY PRIMARY KEY (FirstName));
INSERT INTO 'user_info' VALUES('kim','lim','jim');
INSERT INTO 'user_info' VALUES('tom','tim','zim')"
,$sqliteerror);
$result=sqlite_query($db,"SELECT * from user_info");
echo "<table border=1>";
while($row=sqlite_fetch_array($result,SQLITE_NUM ))
{
echo "<tr>";
for ($i = 0; $i < sizeof($row) ; $i++) {
echo "<td>" . $row[$i] . "</td>";
}
echo "</tr>";
}
echo "</table>";
sqlite_close($db);
?>
答案 0 :(得分:1)
我想要弄明白,只需改变:
ID INTEGER(100) AUTOINCREMENT,
到
ID INTEGER PRIMARY KEY,
并为主键插入一个值为null:
INSERT INTO 'user_info' VALUES(NULL,'tom','bob','zim');
或
INSERT INTO user_info (ID,FirstName,Surname,UserName) VALUES(NULL,'tom','bob','zim');
答案 1 :(得分:0)
您只能将AUTOINCREMENT
与INTEGER PRIMARY KEY
一起使用。将列规格更改为
ID INTEGER PRIMARY KEY AUTOINCREMENT