Re: DB_mysql and multiple conections
| From: | John Lim | Date: | Wed, 05 Sep 2001 16:02:36 +0000 |
| Subject: | Re: DB_mysql and multiple conections | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-1810@lists.php.net to get a copy of this message | ||
I experimented with this for the ADODB library, but i dropped it after I
read this at
http://php.net/manual/en/function.mysql-db-query.php
Note: This function has been deprecated since PHP 4.0.6. Do not use this
function. Use mysql_select_db() and mysql_query() instead.
"Tomas V.V.Cox" <cox@idecnet.com> wrote in message
news:3B96000E.13ED3D17@idecnet.com...
> Hi,
>
> Max Holman <max@blueroo.net>, sent me a patch to solve the problem with
> Pear and Mysql when using multiple conections in the same script. His
> description of the problem:
>
> "Using the MySQL PEAR DB classes, it is not possible to use 2 different
> databases within the same script, unless the Hostname and/or password to
> connect to each database are completely different.
>
> I have implement a fix, which uses mysql_db_query() instead, and
> DB_mysql
> now holds the database name within itsself.
>
> diff output is avaiable at
> http://www.blueroo.net/pear/DB/mysql030901.diff
>
> However, I am unsure how to handle the detection of
> 'DB_ERROR_NODBSELECTED'
> in this instance
>
> Hope this helps"
>
> I couldn't apply his patch but adapt it to the last mysql.php release. I
> ran "make test" and had no problems. Please let me know if someone have
> problems with this patch, before commit it.
>
>
> Tomas V.V.Cox
----------------------------------------------------------------------------
----
> Index: mysql.php
> ===================================================================
> RCS file: /repository/php4/pear/DB/mysql.php,v
> retrieving revision 1.71
> diff -u -r1.71 mysql.php
> --- mysql.php 16 Aug 2001 08:48:56 -0000 1.71
> +++ mysql.php 5 Sep 2001 10:49:09 -0000
> @@ -132,6 +132,7 @@
> return $this->raiseError(DB_ERROR_NODBSELECTED, null,
null,
> null, mysql_error($conn));
> }
> + $this->_database = $dsninfo['database'];
> }
>
> $this->connection = $conn;
> @@ -177,15 +178,15 @@
> $query = $this->modifyQuery($query);
> if (!$this->autocommit && $ismanip) {
> if ($this->transaction_opcount == 0) {
> - $result = @mysql_query('SET AUTOCOMMIT=0',
$this->connection);
> - $result = @mysql_query('BEGIN', $this->connection);
> + $result = @mysql_db_query($this->_database, 'SET
AUTOCOMMIT=0', $this->connection);
> + $result = @mysql_db_query($this->_database, 'BEGIN',
$this->connection);
> if (!$result) {
> return $this->mysqlRaiseError();
> }
> }
> $this->transaction_opcount++;
> }
> - $result = @mysql_query($query, $this->connection);
> + $result = @mysql_db_query($this->_database, $query,
$this->connection);
> if (!$result) {
> return $this->mysqlRaiseError();
> }
> @@ -354,8 +355,8 @@
> function commit()
> {
> if ($this->transaction_opcount > 0) {
> - $result = @mysql_query('COMMIT', $this->connection);
> - $result = @mysql_query('SET AUTOCOMMIT=1',
$this->connection);
> + $result = @mysql_db_query($this->_database, 'COMMIT',
$this->connection);
> + $result = @mysql_db_query($this->_database, 'SET
AUTOCOMMIT=1', $this->connection);
> $this->transaction_opcount = 0;
> if (!$result) {
> return $this->mysqlRaiseError();
> @@ -373,8 +374,8 @@
> function rollback()
> {
> if ($this->transaction_opcount > 0) {
> - $result = @mysql_query('ROLLBACK', $this->connection);
> - $result = @mysql_query('SET AUTOCOMMIT=1',
$this->connection);
> + $result = @mysql_db_query($this->_database, 'ROLLBACK',
$this->connection);
> + $result = @mysql_db_query($this->_database, 'SET
AUTOCOMMIT=1', $this->connection);
> $this->transaction_opcount = 0;
> if (!$result) {
> return $this->mysqlRaiseError();
>