Re: [PDO] Question on Persistent PDO Connections

[email protected] (Ulf Wendel) Fri, 06 Nov 2009 13:54:03 +0100
Newsgroups php.pdo
Message-ID <[email protected]>
Lester Caine schrieb:
> Ulf Wendel wrote:
>> Lukas Kahwe Smith schrieb:
>>> well for mysql traditonally persistent connections came with the risk 
>>> of an unclean session. i guess there is now a solution to clean up 
>>> the session fairly well, making persistent connections more feasible, 
>>
>> COM_CHANGE_USER/mysql_change_user() cleans up the line. The call 
>> itself exists since quite some time. In its early days (say more than 
>> three years ago) it was known to have issues. But its working fine 
>> nowadays.
>>
>> Its possible to clean up the line before reuse, if wanted. Calling 
>> mysql_change_user is the default for ext/mysqli. However, if you know 
>> what you do, you may not want to clean the line for performance reasons.
> 
> Actually Ulf that sounds a little strange when the mechanism to use an 
> existing connection is that your new connection MUST have the same 
> username and password. Ideally I think, there should be nothing 

Not sure if I get what you say.

mysql_change_user() (C API [1], protocol command COM_CHANGE_USER) is the 
MySQL way of resetting an existing connection. After the call the 
connection is as if its new. As server permissions can change between 
putting a connection into a persistent pool and reusing a connection, it 
is necessary to re-authenticate the user.

It is up to the user if you call it or not. That is how things go with 
MySQL.

If you know what you are doing, you can limit resetting things before 
reuse to whatever you want to be reset. If you don't use transactions, 
for example because you use MyISAM, there is no need to issue a 
rollback. Or, if you know that permissions only change during an 
application upgrade once in a quarter, there is no need for an time 
consuming re-authentication with MySQL.

Again, leave it to the user to decide. As said, we made 
mysql_change_user() a default for ext/mysqli. And that is how it should 
be with PDO as well: choice - whatever the default may be.

Ulf

[1] http://dev.mysql.com/doc/refman/5.1/en/mysql-change-user.html