简体   繁体   English

PHP PDO :: lastInsertId()和ATTR_PERSISTENT

[英]PHP PDO::lastInsertId() and ATTR_PERSISTENT

I have almost the same question as this . 我几乎有与相同的问题。

Based on that post I know that PDO::lastInsertId() is safe when called from different connections. 根据该帖子,我知道从不同的连接调用PDO :: lastInsertId()是安全的。 However, does this mean PDO::ATTR_PERSISTENT => true should not be used in the PDO constructor if you want to use PDO::lastInsertId() during that connection? 然而,这是否意味着PDO::ATTR_PERSISTENT => true 应该在PDO构造函数中使用,如果你想要的连接过程中使用PDO :: lastInsertId()?

In other words, if I need to use PDO::lastInsertId() is my application compelled to endure "the overhead of establishing a new connection every time a script needs to talk to a database" as documented in PDO Connections and Connection Management . 换句话说,如果我需要使用PDO :: lastInsertId(),我的应用程序将不得不承受“每次PDO Connections and Connection Management ”中记录的“每次脚本需要与数据库进行通信时建立新连接的开销”。

No, it doesn't mean. 不,这并不意味着。

Doesn't matter who will utilize the same connection after your php script ends its work. 没关系,在您的php脚本结束其工作之后,谁将利用相同的连接。 What matters is that you will have the last inserted id that's performed by this, not another connection. 重要的是,您将获得此操作执行的最后插入的ID,而不是另一个连接。

So feel free to use it with both persistent and not-persistent connections. 因此,可以在持久连接和非持久连接中随意使用它。

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

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