默认情况下,以下代码不会在 sqlite db 中保存“eventid”。我可以看到所有带有 echo 的行,但事件 ID 是 emply ......有什么想法吗?非常感谢。
$now = time();
try{
if (!file_exists("testgb")){
$db = new PDO('sqlite:testgb');
$db->exec("CREATE TABLE guestbook (eventid INTEGER PRIVATE KEY,name VARCHAR(55), message TEXT, date DATETIME)");
}
$db = new PDO('sqlite:testgb');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec("INSERT INTO guestbook (name, message, date) VALUES ('KIRILL', 'Hello!!', datetime($now, 'unixepoch'))");
$res = $db->query("SELECT * FROM guestbook");
foreach ($res as $row){
echo $row['eventid']."<br>";
echo $row['name']."<br>";
echo $row['message']."<br>";
echo $row['date']."<br>";
echo "<hr>";
}
}catch (PDOException $e){
echo $e->getMessage();
}