cvs: php4 /pear/DB mysql.php
| From: | Thomas V.V.Cox | Date: | Thu, 06 Sep 2001 23:44:10 +0000 |
| Subject: | cvs: php4 /pear/DB mysql.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-811@lists.php.net to get a copy of this message | ||
cox Thu Sep 6 19:44:10 2001 EDT
Modified files:
/php4/pear/DB mysql.php
Log:
added a fix to solve the problem with multiple DB instances and different
databases (under equal user/pass/host)
Index: php4/pear/DB/mysql.php
diff -u php4/pear/DB/mysql.php:1.71 php4/pear/DB/mysql.php:1.72
--- php4/pear/DB/mysql.php:1.71 Thu Aug 16 04:48:56 2001
+++ php4/pear/DB/mysql.php Thu Sep 6 19:44:10 2001
@@ -30,6 +30,9 @@
require_once "DB/common.php";
+// global var to detect if the database has changed or not
+$GLOBALS['_DB_mysql_changed_database'] = false;
+
class DB_mysql extends DB_common
{
// {{{ properties
@@ -42,6 +45,7 @@
var $transaction_opcount = 0;
var $autocommit = true;
var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */
+ var $_changed_db = false;
// }}}
// {{{ constructor
@@ -128,9 +132,16 @@
}
if ($dsninfo['database']) {
- if (!@mysql_select_db($dsninfo['database'], $conn)) {
- return $this->raiseError(DB_ERROR_NODBSELECTED, null, null,
- null, mysql_error($conn));
+ // fix to allow calls to different databases in the same script
+ if (!isset($GLOBALS['_DB_mysql_changed_database'])) {
+ $this->_changed_db = false;
+ if (!@mysql_select_db($dsninfo['database'], $conn)) {
+ return $this->raiseError(DB_ERROR_NODBSELECTED, null, null,
+ null, mysql_error($conn));
+ }
+ } else {
+ $GLOBALS['_DB_mysql_changed_database'] = true;
+ $this->_changed_db = $dsninfo['database'];
}
}
@@ -175,6 +186,11 @@
$ismanip = DB::isManip($query);
$this->last_query = $query;
$query = $this->modifyQuery($query);
+ if ($this->_changed_db) {
+ if (!@mysql_select_db($this->_changed_db, $this->connection)) {
+ return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+ }
+ }
if (!$this->autocommit && $ismanip) {
if ($this->transaction_opcount == 0) {
$result = @mysql_query('SET AUTOCOMMIT=0', $this->connection);
@@ -354,6 +370,11 @@
function commit()
{
if ($this->transaction_opcount > 0) {
+ if ($this->_changed_db) {
+ if (!@mysql_select_db($this->_changed_db, $this->connection)) {
+ return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+ }
+ }
$result = @mysql_query('COMMIT', $this->connection);
$result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);
$this->transaction_opcount = 0;
@@ -373,6 +394,11 @@
function rollback()
{
if ($this->transaction_opcount > 0) {
+ if ($this->_changed_db) {
+ if (!@mysql_select_db($this->_changed_db, $this->connection)) {
+ return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+ }
+ }
$result = @mysql_query('ROLLBACK', $this->connection);
$result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);
$this->transaction_opcount = 0;