php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51989 PDO class doesn't connect but reuse open connections
Submitted: 2010-06-03 14:43 UTC Modified: 2010-06-04 10:05 UTC
From: nospam at unclassified dot de Assigned:
Status: Not a bug Package: *Database Functions
PHP Version: 5.3.2 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nospam at unclassified dot de
New email:
PHP Version: OS:

 

 [2010-06-03 14:43 UTC] nospam at unclassified dot de
Description:
------------
The manual says that the PDO class represents a database connection. Thus I assume that when I instantiate two PDO classes, I get two database connections. But instead, when using the same connection data, I do not get a second connection but the first connection is simply reused. I need a separate connection for logging purposes, it cannot use the primary connection that's affected by transactions and all such things.

I do get a separate connection when I connect to "127.0.0.1" instead of "localhost", which is a different string but the same meaning. This is a hack though because there are very limited alternatives to define the same host.

Expected result:
----------------
I expect every PDO instance to actually give me a new connection, at least when another connection is already in use.

Actual result:
--------------
It gives me the old connection that is used for transactions and such. My programme doesn't work then. It needs another connection.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-04 09:38 UTC] mike@php.net
-Status: Open +Status: Feedback
 [2010-06-04 09:38 UTC] mike@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2010-06-04 09:41 UTC] nospam at unclassified dot de
-Status: Feedback +Status: Open
 [2010-06-04 09:41 UTC] nospam at unclassified dot de
Sorry, a script that creates databases and such and also reproduces the bug in 
under 20 lines of code? That's impossible.
 [2010-06-04 10:05 UTC] mike@php.net
-Status: Open +Status: Bogus
 [2010-06-04 10:05 UTC] mike@php.net
Well, than it's impossible to help you, and I have to assume the bug is in your code.

php -r '$p1=new PDO("mysql:dbname=test"); $p2=new PDO("mysql:dbname=test"); $p1->exec("drop table if exists t1"); $p1->exec("create table t1 (id int auto_increment primary key)"); foreach (array($p1,$p2) as $p) $p->exec("insert into t1(id) values(NULL)"); foreach (array($p1,$p2) as $p) var_dump($p->query("SELECT LAST_INSERT_ID()")->fetchAll());'

array(1) {
  [0]=>
  array(2) {
    ["LAST_INSERT_ID()"]=>
    string(1) "1"
    [0]=>
    string(1) "1"
  }
}
array(1) {
  [0]=>
  array(2) {
    ["LAST_INSERT_ID()"]=>
    string(1) "2"
    [0]=>
    string(1) "2"
  }
}

php -r '$p1=new PDO("mysql:dbname=test",null,null,array(PDO::ATTR_PERSISTENT=>1)); $p2=new PDO("mysql:dbname=test",null,null,array(PDO::ATTR_PERSISTENT=>1)); $p1->exec("drop table if exists t1"); $p1->exec("create table t1 (id int auto_increment primary key)"); foreach (array($p1,$p2) as $p) $p->exec("insert into t1(id) values(NULL)"); foreach (array($p1,$p2) as $p) var_dump($p->query("SELECT LAST_INSERT_ID()")->fetchAll());'
array(1) {
  [0]=>
  array(2) {
    ["LAST_INSERT_ID()"]=>
    string(1) "2"
    [0]=>
    string(1) "2"
  }
}
array(1) {
  [0]=>
  array(2) {
    ["LAST_INSERT_ID()"]=>
    string(1) "2"
    [0]=>
    string(1) "2"
  }
}
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Sep 21 16:01:24 2020 UTC