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();
精彩评论