使用PDO获取插入和更新ID [英] Getting the insert and update ID with PDO

查看:78
本文介绍了使用PDO获取插入和更新ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PDO获得mysql_insert_id. 到目前为止,我还没有找到一个可以同时插入和更新的好例子. 有没有人提供完整的代码示例?

Im trying to get the mysql_insert_id using PDO. Thus far i've not found a good example that works with both inserting and updating. Does anyone have a piece of complete code as example?

推荐答案

如果您需要 $pdo->lastInsertId()返回刚刚更新的行的ID(如果需要,我会认真考虑我的设计但嘿...可能是真正的需求),请执行以下更新:

If you need $pdo->lastInsertId() to return the id of the row just updated (I would seriously reconsider my design if I needed it but hey... can be a true need), do the update like this:

 UPDATE tablename  SET some_column='somevalue',id=LAST_INSERT_ID(id);

这篇关于使用PDO获取插入和更新ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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