Вопрос

I have almost the same question as this.

Based on that post I know that PDO::lastInsertId() is safe when called from different connections. 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?

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.

Это было полезно?

Решение

No, it doesn't mean.

Doesn't matter who will utilize the same connection after your php script ends its work. What matters is that you will have the last inserted id that's performed by this, not another connection.

So feel free to use it with both persistent and not-persistent connections.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top