note 54563 added to function.mysql-close

From: Date: Thu, 07 Jul 2005 21:47:36 +0000
Subject: note 54563 added to function.mysql-close
Groups: php.notes 
Request: Send a blank email to php-notes+get-91616@lists.php.net to get a copy of this message
Hi- I have been reading up on DB connections in php/mysql, because I am seeing some strange behavior. It looks to me like the opening and closing of multiple DB connections is not behaving in a clear, expected, or useful fashion. I have a PHP application with a lot of source and functions that are called from included files and I am encountering problems when I try to connect to and manipulate data in different mysql DBs. In particular, I have a function ("A") that is called from within another function ("B"). My function "A" connects to multiple DBs and performs different operations on the data, then returns success or failure. Even though I am explicitly opening a new DB link inside my function and assigning the new DB resource to a variable and using mysql_select_db to select that new DB, and explicitly referencing that variable in my DB-related code, it appears that the code in my function "A" is causing the DB connection used by the function "B" to be dropped or lost. This may be due to the behavior described in previous notes (in order to manage DB connections, you need to keep track of a "reference count" which is incremented and decremented as a program executes). The problem with having to maintain a "reference count" for DB connections is that it can become difficult or impossible to track this count in any but the simplest of applications. In a serious PHP application, with pieces of code being referenced by many other pieces of code on a conditional basis depending upon input parameters and execution flow and multiple connections to multiple databases being opened/closed/created, the reference count will not be predictable. So it seems like there is actually no way in PHP to explicitly open a new and separate DB connection. It seems like all connections are shared during program execution, and you cannot manage your DB connections in PHP the way you can manage all other resources.This seems to me to be incredibly LAME. If PHP cannot allow a developer to explicitly: 1. open a DB connection 2. use the connection privately 3. close the connection then PHP is useless for serious DB applications. How can you have a multiuser DB app that is performing operations on multiple DBs without the ability to EXPLICITLY define what DBs are being operated on at any given point in time? Without that ability, how can you have any assurance that your code is updating the DB you think it is???? Can you think of ANY language that has a function (mysql_close) designed to clear out temprary objects and free resources, that DOESN'T actually do any of that, but instead just decrements a reference count? WTF? No way to explicitly close a DB connection? Even if I pass in the resource link? LAME. No way to avoid hijacking DB connections used by other parts of the code? LAME. I would like to ask that this comment NOT be removed from this page - maybe someone will read it and they won't end up like me with a PHP app that has problems managing DB connections, and no clear way to resolve the issues. ---- Manual Page -- http://www.php.net/manual/en/function.mysql-close.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54563 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54563&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54563&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54563&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54563&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54563&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54563&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54563&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91616) next »