473,692 Members | 2,216 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PEAR::DB disconnect closes all database connections

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_repo rting(E_ALL);
03
04***require_on ce('DB.php');
05
06***define('DB _TYPE',*****'my sql');
07***define('DB _HOST',*****'lo calhost');
08***define('DB _PORT',*****330 6);
09***define('DB _USERNAME',*'xx x');
10***define('DB _PASSWORD',*'yy y');
11***define('DB _DATABASE',*'zz z');
12
13***function*d b_open()
14***{
15*****$dsn*=*D B_TYPE*.*'://'*.*DB_USERNAME *.*':'*.*DB_PAS SWORD*.*'@'*.
16*****DB_HOST* .*':'*.*DB_PORT *.*'/'*.*DB_DATABASE ;
17*****$db**=*D B::connect($dsn );
18*****return*$ db;
19***}
20
21***function*a ()
22***{
23*****$db*=*db _open();
24
25*****b();
26
27*****echo*'qu ery*in*a()<br*/>';
28*****$test*=* $db->getAll('select ***from*abc');
29*****$db->disconnect() ;
30
31*****if*(DB:: isError($test))
32*******echo*$ test->getMessage()*. *'<br*/><br*/>'*.*$test->getDebugInfo() ;
33***}
34
35***function*b ()
36***{
37*****$db*=*db _open();
38
39*****echo*'qu ery*in*b()<br*/>';
40*****$test*=* $db->getAll('select ***from*abc');
41*****$db->disconnect() ;
42
43*****if*(DB:: isError($test))
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
Jul 17 '05 #1
3 2889
Sven Jacobs <sv*********@we b.de> wrote in message
news:<cg******* ******@news.t-online.com>...

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. .... Why does a method of a local object interfere with another local object?!


It has NOTHING to do with objects and everything to do with underlying
database interface:

If a second call is made to mysql_connect() with the same arguments,
no new link will be established, but instead, the link identifier
of the already opened link will be returned. The new_link parameter
modifies this behavior and makes mysql_connect() always open a new
link, even if mysql_connect() was called before with the same
parameters.

Note: The new_link parameter became available in PHP 4.2.0

http://www.php.net/manual/en/function.mysql-connect.php

Now let's look at your code (compressed to highlight the point):

21 function a()
22 {
23 $db = db_open();
25 b();
29 $db->disconnect() ;
33 }
35 function b()
36 {
37 $db = db_open();
41 $db->disconnect() ;
45 }
47 a();

When function a() calls function b(), b() DOES NOT ESTABLISH A NEW
LINK TO THE DATABASE, but, rather, uses the one established by a().
So when b() closes the link, it closes the link established by a(),
and a() is no longer able to use it.

Cheers,
NC
Jul 17 '05 #2
Nikolai Chuvakhin wrote:
When function a() calls function b(), b() DOES NOT ESTABLISH A NEW
LINK TO THE DATABASE, but, rather, uses the one established by a().
So when b() closes the link, it closes the link established by a(),
and a() is no longer able to use it.


So why did the code work before upgrading PEAR::DB? :-/ Did they pass the
new_link parameter and now removed it? Possible...

Can I safely remove all $db->disconnect() 's from my code and PHP will
disconnect from the db automaticly if the script execution ends?

--
Sincerely
Sven Jacobs
Jul 17 '05 #3
Sven Jacobs <sv*********@we b.de> wrote in message
news:<cg******* ******@news.t-online.com>...

Can I safely remove all $db->disconnect() 's from my code and PHP will
disconnect from the db automaticly if the script execution ends?


Yes, absolutely.

Cheers,
NC
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2396
by: kain | last post by:
hi there, I'm currently converting a MySQL application to PostgreSQL, and I hacked this app to support PEAR::Db . after some good coding days, I've found a problem: mysql_insert_id on pear::db . I've those two piece of code, the first is part of a class: --------- function connect($layer,$host,$db_port,$db_name,$user,$pass) { $dsn = "$layer://$user:$pass@$host:$db_port/$db_name";
0
1507
by: Analysis&Solutions | last post by:
Greetings: Crack open the beer, PEAR DB 1.6.0 is here! (Hey, I'm a bit giddy with excitement that my intense work during the past seven weeks has come to fruition.) For those unfamiliar with PEAR DB, it's a package of PHP classes that provide an object oriented API with common methods of accessing thirteen of PHP's database driver extensions: dBase, FrontBase, InterBase, Informix, mSQL, MS SQL Server,
0
1358
by: Derek Battams | last post by:
With PHP5RC2, DB::connect() is not returning the correct type of object. #!/usr/local/bin/php <?php require_once("DB.php"); $dsn = "odbc://db2inst1:badpasswd@testdb"; $db = DB::connect($dsn); echo $db->getMessage(); if(DB::isError($db))
1
2773
by: James | last post by:
Hey everyone, I have a really obscure but impassable problem with a reasonably simple piece of php/PEAR DB/MySQL code When calling several stored procs the first call succeeds, but subsequent calls fail no matter which SP is called first it always works, and the rest fail... with: >>>
8
1566
by: lawrence k | last post by:
I wrote a simple CMS for personal use. I'm thinking of using it for other clients now. It's use of the database is slow and inefficient. I'm thinking of switching to the PEAR class listed here: http://pear.php.net/package/DB What do people think of it?
3
1943
by: Paul | last post by:
I have tested my logic flow and determined that the conversion from what is given to the $db->prepare() statement and what is stored in the database iteslf goes from: "I'm helpful" to "I'm helpful" is converted by pear's DB. I am using $db->prepare() statement. When I do
4
2747
by: andy | last post by:
Hey All, When I have DB.php (PEAR) in the root directory of my project it works ok using require "DB.php"; When I put it in a seperate folder and call it using require "classes/DB.php";
3
3505
by: mpar612 | last post by:
I am stumped. Below is my code and it doesn't work (I removed the $login info for posting). PHP Code: require 'PEAR/DB.php'; // Connect to the database $db = DB::connect($login); if (DB::isError($db)) { die ("Can't connect: " . $db->getMessage()); }
2
2064
by: daralthus | last post by:
Hello! I would like to ask your help, i have founded a great code here: http://www.jamescaws.co.uk/2008/07/dynamically-count-exit-link-clicks-throughs-using-javascript-php/ but it uses Pear DB for the database connection. the problem is that it don't works, actually the php don't writes anything in the table and i don't get any error when i add the if (PEAR::isError($db)) { die($db->getMessage());} code, so not the connection... Then i...
0
9083
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8961
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8800
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8801
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6459
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4324
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1957
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.