开发者

In PHP, when using PDO with pgSQL how to get the value of "RETURNING" clause in the original INSERT sql query

In PHP, I am using PDO with the pgSQL drivers. I wanted to know how to get the value of the "RETURNING" clause given in the INSERT sql query. My current code looks like this,

$quer开发者_JAVA百科y = 'INSERT INTO "TEST" (firstname, lastname) VALUES ('John', 'Doe') RETURNING user_id';
$queryHandle = $connection->prepare($query);
$queryHandle->execute();

Obviously

$queryHandle->execute();

returns TRUE or FALSE. But I wanted to get the value of "user_id" if the insert was successful. Can you guys give me a pointer as to how to go about it? Thanks.


$ret = $queryHandle->fetchColumn();

Will return a single value instead of an array.


Did you tried to treat the command as a select returning, running

$ret=$queryHandle->fetchAll();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜