开发者

Syntax for "RETURNING" clause in Mysql PDO

开发者 https://www.devze.com 2022-12-29 10:32 出处:网络
I\'m trying to add a record, and at the same time return the id of that record 开发者_StackOverflowadded. I read it\'s possible to do it with a RETURNING clause.

I'm trying to add a record, and at the same time return the id of that record 开发者_StackOverflowadded. I read it's possible to do it with a RETURNING clause.

$stmt->prepare("INSERT INTO tablename (field1, field2) 
                               VALUES (:value1, :value2)
                          RETURNING id");

but the insertion fails when I add RETURNING. There is an auto-incremented field called id in the table being added to.

Can someone see anything wrong with my syntax? or maybe PDO does not support RETURNING?


I don't think it has anything to do with PDO supporting it or not. RETURNING is supported by Oracle and PostgreSQL but not by MySQL.

Use PDO::lastInsertId instead.

0

精彩评论

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