简体   繁体   English

如何使用php从mysql获取当前的user_id?

[英]How to get the current user_id from the mysql using php?

I need to know the current user_id where this user_id is an auto increment column. 我需要知道当前的user_id ,其中该user_id是自动递增列。

How to find the current user_id using php code? 如何使用PHP代码查找当前的user_id?

Suppose, the last user_id is 23. 假设最后一个user_id为23。

The next created user will have an user_id of 24. How to know this after executing the related INSERT query? 下一个创建的用户的user_id为24。执行相关的INSERT查询后如何知道?

To get the last added user id, where id is auto-increment: 要获取最后添加的用户ID,其中ID为自动递增:

$n = mysql_query("SELECT max(id) FROM tablename");

Thus, the return value of mysql_query gives it back to you. 因此, mysql_query的返回值将其返回给您。 In your example, $n will be 24. 在您的示例中, $n将为24。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM