|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 05:00:01 2025 UTC |
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" } }