php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66740 PDO MySQL not allow create multi connections from one PHP session
Submitted: 2014-02-19 11:41 UTC Modified: 2014-02-19 14:52 UTC
From: mikhail dot v dot gavrilov at gmail dot com Assigned:
Status: Not a bug Package: PDO MySQL
PHP Version: 5.5.9 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 + 36 = ?
Subscribe to this entry?

 
 [2014-02-19 11:41 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-19 12:07 UTC] tony2001@php.net
-Status: Open +Status: Not a bug
 [2014-02-19 12:07 UTC] 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 14:52 UTC] mikhail dot v dot gavrilov at gmail dot com
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?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC