插入后的mySQL返回索引 [英] mySQL return index after insert

查看:64
本文介绍了插入后的mySQL返回索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有的方式是我设置了一个运行良好的插入命令 它将条目添加到我的数据库中...因为我想使用从第一次插入获得的唯一索引将其他条目插入其他表中,所以我进行查询以获取索引,然后将其重用其他插入... 虽然这很好...我相信必须有更好的方法 有什么建议? 谢谢:)

the way i have it is that I set up an insert command which works well it add the entry to my DB ...since i want to insert other entries in other tables using the unique index that was obtained from the first insertion I do a query obtain the index then reuse it other insert... though this works fine...I am sure there has to be a better way any suggestions? thank you :)

推荐答案

为您可以使用的自动增量索引

for the autoincrement index you can use

SELECT LAST_INSERT_ID()

在PHP中

mysql_insert_id(),如果您恰巧使用该语言

or mysql_insert_id() in PHP if you happen to use this language

这篇关于插入后的mySQL返回索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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