cvs: php4 /pear/DB mysql.php

From: Date: Mon, 31 Dec 2001 18:49:54 +0000
Subject: cvs: php4 /pear/DB mysql.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1784@lists.php.net to get a copy of this message
cox Mon Dec 31 13:49:54 2001 EDT Modified files: /php4/pear/DB mysql.php Log: Always use mysql_select_db() before each query to ensure a working support of multiple database connections in the same script Index: php4/pear/DB/mysql.php diff -u php4/pear/DB/mysql.php:1.82 php4/pear/DB/mysql.php:1.83 --- php4/pear/DB/mysql.php:1.82 Tue Dec 11 10:31:17 2001 +++ php4/pear/DB/mysql.php Mon Dec 31 13:49:54 2001 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.82 2001/12/11 15:31:17 sebastian Exp $ +// $Id: mysql.php,v 1.83 2001/12/31 18:49:54 cox Exp $ // // Database independent query interface definition for PHP's MySQL // extension. @@ -32,9 +32,6 @@ 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 @@ -47,7 +44,7 @@ var $transaction_opcount = 0; var $autocommit = true; var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */ - var $_changed_db = false; + var $_db = false; // }}} // {{{ constructor @@ -137,17 +134,12 @@ } if ($dsninfo['database']) { - // fix to allow calls to different databases in the same script - if (empty($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']; + 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 + $this->_db = $dsninfo['database']; } $this->connection = $conn; @@ -191,10 +183,8 @@ $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 (!@mysql_select_db($this->_db, $this->connection)) { + return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); } if (!$this->autocommit && $ismanip) { if ($this->transaction_opcount == 0) { @@ -392,10 +382,8 @@ 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); - } + if (!@mysql_select_db($this->_db, $this->connection)) { + return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); } $result = @mysql_query('COMMIT', $this->connection); $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection); @@ -416,10 +404,8 @@ 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); - } + if (!@mysql_select_db($this->_db, $this->connection)) { + return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); } $result = @mysql_query('ROLLBACK', $this->connection); $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);

« previous php.pear.cvs (#1784) next »