Syntax for “RETURNING” clause in Mysql PDO

我与影子孤独终老i 提交于 2019-12-23 15:41:12

问题


I'm trying to add a record, and at the same time return the id of that record added. 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?


回答1:


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.



来源:https://stackoverflow.com/questions/2796244/syntax-for-returning-clause-in-mysql-pdo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!