无法从自动增量返回id [英] Trouble returning id from auto increment

查看:63
本文介绍了无法从自动增量返回id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人帮忙。我搜索了大量的论坛和网站,但似乎没有人给我答案。


我已经将信息发布到我的数据库,我希望返回id使用mysqli_insert_id()函数。我把它发布到php。请有人帮忙,因为没有返回整数而有点生气。

Could someone please help. I''ve searched alot of forums and website but none seem to give me the answer.

I''ve posted info to my database and i''m looking to return the id using the mysqli_insert_id() function. I''m posting it to php. Please someone help, going a bit mad as no integer is returned.

展开 | 选择 | Wrap | 行号

推荐答案

mysqli_insert_id()函数返回由具有AUTO_INCREMENT属性的列的表上的查询生成的ID。如果最后一个查询不是INSERT或UPDATE语句,或者如果修改后的表没有具有AUTO_INCREMENT属性的列,则此函数将返回零。


注意:使用LAST_INSERT_ID()函数执行INSERT或UPDATE语句也会修改mysqli_insert_id()函数返回的值。

返回值

上一个查询更新的AUTO_INCREMENT字段的值。如果连接上没有先前查询或查询未更新AUTO_INCREMENT值,则返回零。


注意:如果数字大于最大int值,mysqli_insert_id()将返回一个字符串。
The mysqli_insert_id() function returns the ID generated by a query on a table with a column having the AUTO_INCREMENT attribute. If the last query wasn''t an INSERT or UPDATE statement or if the modified table does not have a column with the AUTO_INCREMENT attribute, this function will return zero.

Note: Performing an INSERT or UPDATE statement using the LAST_INSERT_ID() function will also modify the value returned by the mysqli_insert_id() function.

Return Values
The value of the AUTO_INCREMENT field that was updated by the previous query. Returns zero if there was no previous query on the connection or if the query did not update an AUTO_INCREMENT value.

Note: If the number is greater than maximal int value, mysqli_insert_id() will return a string.


mysqli语句是mysqli_stmt_insert_id 。但是,文档中还没有进一步的描述,但它应该像[php] mysqli_stmt_insert_id(
The mysqli statement for this is mysqli_stmt_insert_id. However, there is no further description (yet) in the documenation, but it should be something like[php]mysqli_stmt_insert_id(


result); [/ php]如果你不确定你能不能总是使用MySqli的LAST_INSERT_ID()函数,你的代码就像:[php] if(
result);[/php]If you are not sure you can always use the LAST_INSERT_ID() function of MySqli and your code would then be something like:[php]if(


这篇关于无法从自动增量返回id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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