PDO postgresql 最后插入的 id return 'false' 或 -1

PDO postgresql last inserted id return 'false' or -1

我有密码

$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”

回到家,我自己明白该做什么了

$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();    
$result = $sth->fetch(PDO::FETCH_ASSOC);    
echo "ID - ". $result["id"];

很简单