Dear newsgroup,
I've upgraded to PEAR::DB 1.6.5 recently. Unfortunately now the database
connection doesn't work as expected anymore :( The problems seems to be the
method disconnect(), which now closes the database connections of _all_
database objects. I ask myself if this is intentional or a bug. Below a
code example:
01 <?php
02 error_reporting (E_ALL);
03
04 require_once('D B.php');
05
06 define('DB_TYPE ', 'mysql');
07 define('DB_HOST ', 'localhost');
08 define('DB_PORT ', 3306);
09 define('DB_USER NAME', 'xxx');
10 define('DB_PASS WORD', 'yyy');
11 define('DB_DATA BASE', 'zzz');
12
13 function db_open()
14 {
15 $dsn = DB_TYPE . '://' . DB_USERNAME . ':' . DB_PASSWORD . '@' .
16 DB_HOST . ':' . DB_PORT . '/' . DB_DATABASE;
17 $db = DB::connect($ds n);
18 return $db;
19 }
20
21 function a()
22 {
23 $db = db_open();
24
25 b();
26
27 echo 'query in a()<br />';
28 $test = $db->getAll('sele ct * from abc');
29 $db->disconnect() ;
30
31 if (DB::isError($t est))
32 echo $test->getMessage() . '<br /><br />' . $test->getDebugInfo() ;
33 }
34
35 function b()
36 {
37 $db = db_open();
38
39 echo 'query in b()<br />';
40 $test = $db->getAll('sele ct * from abc');
41 $db->disconnect() ;
42
43 if (DB::isError($t est))
44 echo $test->getMessage() . '<br /><br />' . $test->getDebugInfo() ;
45 }
46
47 a();
48 ?>
In function a() function b() is called which creates a local database
object, does some stuff on the database and then closes its connection.
That worked up to now. Since upgrading PEAR::DB it seems like the
disconnect() of the database object from b() also disconnects the object
from a() because I get the error "DB Error: no database selected" in row 28
of the script. If I comment out the call of b() at row 25 everything works
as expected. I was able to reproduce this behavior with the PHP version
4.3.8 and 5.0.1. Why does a method of a local object interfere with another
local object?!
--
Sincerely
Sven Jacobs
I've upgraded to PEAR::DB 1.6.5 recently. Unfortunately now the database
connection doesn't work as expected anymore :( The problems seems to be the
method disconnect(), which now closes the database connections of _all_
database objects. I ask myself if this is intentional or a bug. Below a
code example:
01 <?php
02 error_reporting (E_ALL);
03
04 require_once('D B.php');
05
06 define('DB_TYPE ', 'mysql');
07 define('DB_HOST ', 'localhost');
08 define('DB_PORT ', 3306);
09 define('DB_USER NAME', 'xxx');
10 define('DB_PASS WORD', 'yyy');
11 define('DB_DATA BASE', 'zzz');
12
13 function db_open()
14 {
15 $dsn = DB_TYPE . '://' . DB_USERNAME . ':' . DB_PASSWORD . '@' .
16 DB_HOST . ':' . DB_PORT . '/' . DB_DATABASE;
17 $db = DB::connect($ds n);
18 return $db;
19 }
20
21 function a()
22 {
23 $db = db_open();
24
25 b();
26
27 echo 'query in a()<br />';
28 $test = $db->getAll('sele ct * from abc');
29 $db->disconnect() ;
30
31 if (DB::isError($t est))
32 echo $test->getMessage() . '<br /><br />' . $test->getDebugInfo() ;
33 }
34
35 function b()
36 {
37 $db = db_open();
38
39 echo 'query in b()<br />';
40 $test = $db->getAll('sele ct * from abc');
41 $db->disconnect() ;
42
43 if (DB::isError($t est))
44 echo $test->getMessage() . '<br /><br />' . $test->getDebugInfo() ;
45 }
46
47 a();
48 ?>
In function a() function b() is called which creates a local database
object, does some stuff on the database and then closes its connection.
That worked up to now. Since upgrading PEAR::DB it seems like the
disconnect() of the database object from b() also disconnects the object
from a() because I get the error "DB Error: no database selected" in row 28
of the script. If I comment out the call of b() at row 25 everything works
as expected. I was able to reproduce this behavior with the PHP version
4.3.8 and 5.0.1. Why does a method of a local object interfere with another
local object?!
--
Sincerely
Sven Jacobs
Comment