"RETURNING"的语法Mysql PDO中的子句 [英] Syntax for "RETURNING" clause in Mysql PDO

查看:371
本文介绍了"RETURNING"的语法Mysql PDO中的子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一条记录,同时返回添加的该记录的ID.我读到可以用RETURNING子句来做到这一点.

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");

,但是当我添加RETURNING时插入失败.在要添加到的表中,有一个名为idauto-incremented字段.

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

有人可以看到我的语法有什么问题吗?还是PDO不支持RETURNING?

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

推荐答案

我认为这与PDO是否支持它无关. Oracle和PostgreSQL支持RETURNING,但MySQL不支持.

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.

改用 PDO::lastInsertId .

这篇关于"RETURNING"的语法Mysql PDO中的子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆