php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24206 PEAR::DB does not work properly with multiple databases
Submitted: 2003-06-16 11:43 UTC Modified: 2003-06-21 13:13 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: fretnoiz at yandex dot ru Assigned:
Status: Not a bug Package: PEAR related
PHP Version: 4.3.2 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fretnoiz at yandex dot ru
New email:
PHP Version: OS:

 

 [2003-06-16 11:43 UTC] fretnoiz at yandex dot ru
Description:
------------
If I create two different objects for database access, one of them does not work.
For example, one DB object is connected to MySQL, second is connected to Interbase. Interbase does not return results properly.

Reproduce code:
---------------
define('DB_DSN1', 'mysql://max:max@localhost/autogarant');
define('DB_DSN2',
 'ibase://SYSDBA:masterkey@localhost/C:\IB\autogarant');

$siteDB =& DB::connect(DB_DSN1);
$cisDB =& DB::connect(DB_DSN2);

$result1 =& $siteDB->query("SELECT NAME FROM kod");

if ($row = $result1->fetchRow(DB_FETCHMODE_ASSOC)) {
    $code = $row['NAME'];
    echo $code . "<br>\n";

    $result2 =& $cisDB->query("SELECT NAME FROM kod WHERE NAME='$code'");
    print_r($result2->fetchRow());
    echo "<br>\n";
}


Expected result:
----------------
The tables in the DBs contain the same data so i expect to get equivalent records.

006.905
Array ( [0] => 006.905 ) 

Actual result:
--------------
006.905

Fatal error: Call to undefined function: fetchrow() in c:\Web\htdocs\test_pear.php on line 23


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-16 12:45 UTC] cox@php.net
$result2 =& $cisDB->query("SELECT NAME FROM kod WHERE
NAME='$code'");
print_r($result2->fetchRow());

"Fatal error: Call to undefined function: fetchrow() in
c:\Web\htdocs\test_pear.php on line 23"

The problem seems that you are not checking for errors. At the top of your code put the following lines:

function pe($obj) {
    echo $obj->toString();
}
PEAR::setErrorHandler(PEAR_ERROR_CALLBACK, 'pe');

and try again.

 [2003-06-16 15:23 UTC] fretnoiz at yandex dot ru
SORRY!!
I've submitted the result which I didn't want to reproduce

Actual result is following
--------------------------
006.905

Warning: ibase_fetch_row(): supplied argument is not a valid InterBase result resource in d:\php4\pear\DB\ibase.php on line 214
 [2003-06-17 03:27 UTC] arnaud@php.net
Have you tried the code provided by Tomas ?

Additionnally you can die on the error

function pe($obj) {
    die($obj->toString());
}
PEAR::setErrorHandler(PEAR_ERROR_CALLBACK, 'pe');
 [2003-06-17 05:59 UTC] fretnoiz at yandex dot ru
Yes, I've tried but error handler was not called and the result remained the same. Additionally, I've reproduced the same result in Linux environment.
 [2003-06-17 06:28 UTC] arnaud@php.net
So, if you do a 

PEAR::setErrorHandling(PEAR_ERROR_DIE);

What does it give ?

alternatively you can try the following

$result2 =& $cisDB->query("SELECT NAME FROM kod WHERE
NAME='$code'");

if (DB::isError($result2)) {
   die($result2->getErrorMessage() . ' ' . $result2->getUserinfo());
}
 [2003-06-17 06:32 UTC] arnaud@php.net
BTW, not sure about that but try removing the reference

PEAR::setErrorHandling(PEAR_ERROR_DIE);

$result2 = $cisDB->query("SELECT NAME FROM kod WHERE
NAME='$code'");
    print_r($result2->fetchRow());
    echo "<br>\n";
}
 [2003-06-17 09:11 UTC] fretnoiz at yandex dot ru
If I do a PEAR::setErrorHandling(PEAR_ERROR_DIE);
output is following
---
006.905

Warning: ibase_fetch_row(): supplied argument is not a valid InterBase result resource in c:\Web\htdocs\pear\DB\ibase.php on line 214
---
and testing $result2 for error gives nothing

I've also noticed that if I remove WHERE clause i.e.
$result2 =& $cisDB->query("SELECT NAME FROM kod");
the script works fine and I successfully get the first row from interbase table:
006.905
Array ( [0] => 006.905 )

But when I change connection order the error returns:
$cisDB =& DB::connect(DB_DSN2);
$siteDB =& DB::connect(DB_DSN1);

$result1 =& $siteDB->query("SELECT NAME FROM kod");

if ($row = $result1->fetchRow(DB_FETCHMODE_ASSOC)) {
    $code = $row['NAME'];
    echo $code . "<br>\n";

    $result2 =& $cisDB->query("SELECT NAME FROM kod WHERE
NAME='$code'");
if (DB::isError($result2)) {
   die($result2->getErrorMessage() . ' ' . $result2->getUserinfo());
}
    print_r($result2->fetchRow());
    echo "<br>\n";
}

After that if I remove check "if (DB::isError($result2)) {"
I get correct result again. =))

It seems that two database objects are not isolated from each other...
 [2003-06-17 09:40 UTC] arnaud@php.net
works fine with two mysql databases. I don't know what's wrong
 [2003-06-17 10:14 UTC] fretnoiz at yandex dot ru
Yes, I also noticed that mysql databases work fine.
Maybe the problem is in the interbase driver?
 [2003-06-21 13:13 UTC] cox@php.net
I was not able to reproduce the problem with this code:

<?
require_once "DB.php";
define('DB_DSN1', 'mysql://...');
define('DB_DSN2', 'ibase://...');
$siteDB =& DB::connect(DB_DSN1);
$cisDB  =& DB::connect(DB_DSN2);

$result1 =& $siteDB->query("SELECT N FROM pearquote");

if ($row = $result1->fetchRow(DB_FETCHMODE_ASSOC)) {
    $code = $row['N'];
    echo $code . "\n";

    $result2 =& $cisDB->query("SELECT N FROM pearquote WHERE N='$code'");
    if (DB::isError($result2)) {
        die($result2->toString());
    }
    $row2 = $result2->fetchRow(DB_FETCHMODE_ASSOC);
    echo $row2['N'] . "\n";
}
?>
Output:
12.3
12.3000001907

Notes:
DSN1 is a mysql valid dsn and DSN2 a valid interbase dsn.
Results differ because the column is defined as FLOAT and interbase seems to "strangely" output it.

I guess the problem is in the use of an old version of the ibase pear db driver/php or a problem with your code.

Please download the lastest version from CVS and try again, with this exact test code. FYI a new Pear DB release will be announced in few days.

Thanks,

Tomas V.V.Cox


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 22 04:01:29 2024 UTC