It is safe to use $mysqli->insert_id for assign to

2020-04-30 09:52发布

I've a forum script that makes for every new topic a "container" and assign to it each post linked to the topic.

So, when I open a new topic my script makes a new row in forum_topics and a new row in forum_posts.

In forum_posts it put into parent column the id of the topic container.

For know who is the container of the post I'm creating I use:

$mysqli->insert_id

I'd like to know if it is safe, I think to two users who open a new topic at the same time... It is a plausible problem?

标签: php mysqli
1条回答
老娘就宠你
2楼-- · 2020-04-30 10:45

Yes it is safe.
Each PHP process uses separate connection and this variable contains inserted id from this very connection

查看更多
登录 后发表回答