Bug #66740 [Nab]: PDO MySQL not allow create multi connections from one PHP session
| From: | mikhail dot v dot gavrilov at gmail dot com | Date: | Wed, 19 Feb 2014 14:52:10 +0000 |
| Subject: | Bug #66740 [Nab]: PDO MySQL not allow create multi connections from one PHP session | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184362@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66740&edit=1
ID: 66740
User updated by: mikhail dot v dot gavrilov at gmail dot com
Reported by: mikhail dot v dot gavrilov at gmail dot com
Summary: PDO MySQL not allow create multi connections from
one PHP session
Status: Not a bug
Type: Bug
Package: PDO MySQL
Operating System: Linux
PHP Version: 5.5.9
Block user comment: N
Private report: N
New Comment:
no no no please
I am use persistent connection for improving connection speed and I really need this. Because I am
to connect to remote base in DMZ it's so slow: (. I just want to grab next yet another ready
MySQL connection from PDO connection pool. Why it behavior can not be implemented?
Previous Comments:
------------------------------------------------------------------------
[2014-02-19 12:07:15] tony2001@php.net
There is no way to force a new _persistent_ connection for any PHP extension and this is not a bug.
The point is that persistent connections are cached and looked up based on their parameters, so no
wonder your code doesn't work as you expected.
Removing the persistent flag fixes it.
------------------------------------------------------------------------
[2014-02-19 11:41:31] mikhail dot v dot gavrilov at gmail dot com
Description:
------------
PDO MySQL not allow create multi connections from one PHP session
Test script:
---------------
#!/usr/bin/php
<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
$dsn = 'mysql:dbname=test;unix_socket=/var/lib/mysql/mysql.sock';
$user = 'root';
$pass = '';
$connection1 = new PDO( $dsn,
$user,
$pass,
array( PDO::ATTR_PERSISTENT => true,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false,
PDO::ATTR_AUTOCOMMIT => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
)
);
$connection2 = new PDO( $dsn,
$user,
$pass,
array( PDO::ATTR_PERSISTENT => true,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false,
PDO::ATTR_AUTOCOMMIT => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
)
);
$sth1 = $connection1->query('select 1');
$sth2 = $connection2->query('select 2');
unset($connection1);
unset($connection2);
echo("It's works");
?>
Expected result:
----------------
I am expected that I can send first query for connection1 and second query for connection2.
But I see what still uses one connection :(
Actual result:
--------------
We have
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General
error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using
PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you
may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.' in
/home/crmdev/www/bes/mysql_multi_connection_bug.php:35
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66740&edit=1