Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.12.2

Request #2865 don't use mysql_select_db on each action
Submitted: 2004-12-01 11:17 UTC
From: andre dot steffens at adress-research dot de Assigned:
Status: Duplicate Package: DB
PHP Version: 4.3.9 OS: Win2k
Roadmaps: (Not assigned)    
Subscription  


 [2004-12-01 11:17 UTC] andre dot steffens at adress-research dot de
Description: ------------ At the moment on each action (like query, etc.) a mysql_select_db() is done. This costs performance and it would be nice to do it only if it is required. I think it could done with a private method like this: function _select_db($db, $connection) { static lastdb; if ($lastdb != $this->_db) { if (!@mysql_select_db($this->_db, $this->connection)) { return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); } $lastdb=$this->_db; } }

Comments

 [2004-12-03 16:42 UTC] andre dot steffens at adress-research dot de
my last solution doesn't work, try the following: function selectdb($db = null) { static $lastdb; if (!isset($db)) { $db = $this->_db; } if ((($lastdb != $db && !$this->_new) || !$this->_db) && $db) { unset($this->_db); if (!@mysql_select_db($db, $this->connection)) { switch (mysql_errno($conn)) { case 1049: return $this->raiseError(DB_ERROR_NOSUCHDB, null, null, null, @mysql_error($conn)); case 1044: return $this->raiseError(DB_ERROR_ACCESS_VIOLATION, null, null, null, @mysql_error($conn)); default: return $this->raiseError(DB_ERROR, null, null, null, @mysql_error($conn)); } } } $this->_db = $lastdb = $db; if (!$this->_db) { return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); } return DB_OK; } $this->_new is from my connect. I set it to true if a new connection is created (see #2814)
 [2005-01-17 07:59 UTC] danielc
This is a duplicate of request 1905.
 [2005-06-17 16:45 UTC] kevinrsours at yahoo dot com
There are two issues here. 1) Allowing new database connections when connect is called. 2) Removing the calls to mysql_db_select when they are unnecesary. The first was addressed by 1905, but the second is still a problem. A bit of testing I did a while back showed that mysql_db_select, while harmless in terms of results, is more expensive then I expected. It would be nice to eliminate the calls to mysql_db_select if possible (at the very least if you always create new connections you don't need this)