Thursday, 15 August 2013

php - SQLite doesn't save a primary key -



php - SQLite doesn't save a primary key -

the next code doesn't save "eventid" in sqlite db default. can see rows echo event id emply... ideas why? lot.

$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 guestbook (name, message, date) values ('kirill', 'hello!!', datetime($now, 'unixepoch'))"); $res = $db->query("select * guestbook"); foreach ($res $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(); }

would add together autoincrement event id? , primary key?

$db->exec("create table guestbook (eventid integer primary key autoincrement,name varchar(55), message text, date datetime)");

php sql sqlite3 pdo auto-increment

No comments:

Post a Comment