php中怎么让主键自增长,如果我的主键不能自动增加,如何用PHP获取最后插入的ID...

请转到本页的评论部分。

http://php.net/manual/en/function.mysql-insert-id.php

你应该看到一些可能适合你的方法。

我会尝试插入特定的time_stamp,然后再次调用time_stamp insert。

戴夫在这篇评论中做了很好的解释。引用他..

There is a lot of incorrect info here on "don't use AI" and "using max

is equivalent". Then you have people improperly advising you to use

psuedo-random numbers

If you're really worried about the AI field not returning because of

the inherent race conditions, just do a select statement based on the

vars you just input. If your vars are not unique, DON'T use these

psuedo-random numbers. When you have enough iterations, the

probability that the one of these randoms becomes a duplicate gets

pretty high.

Instead, just use the unix timestamp. However, don't use

UNIX_TIMESTAMP() in your query, because if you do, when you run your

select statement right after, there's a possibility that you'll end up

with a different timestamp.

Since date() continues to count up during the execution of the script,

simply store date(U) into a variable or definition. Then insert and

select based on that. Assuming you're not using mysql procedures:

define(UNIX_TIMESTAMP, date('U'));

$db->query("insert into table values('', 'a', 'b', 'c', 'd', '".UNIX_TIMESTAMP."'");

$res = $db->query("select id from table where a_col = 'a' and b_col = 'b' and c_col = 'c' and d_col = 'd' and temp_id = 'UNIX_TIMESTAMP'");

//...

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值