【发布时间】:2017-11-03 13:40:07
【问题描述】:
我有代码
$dbh = new PDO("pgsql:host=localhost; port=5432; dbname=gpd; user=postgres; password=postgres");
$sth = $dbh->prepare("INSERT INTO res (res_name, res_order) VALUES ('London', 1)");
$sth->execute();
$id = $dbh->lastInsertId();
echo $id;
记录插入,但 $id 为空。
我尝试执行查询
INSERT INTO res (res_name, res_order) VALUES ('London', 1) RETURNING id
并收到一个值“-1”
【问题讨论】:
-
可以分享
res的表结构吗? -
CREATE TABLE res (id SERIAL PRIMARY KEY, res_name VARCHAR(100) DEFAULT '' NOT NULL, res_order INT DEFAULT 1 NOT NULL)
标签: postgresql pdo lastinsertid