PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB » Bug #2865

don't use mysql_select_db on each action

Details

Request #2865don't use mysql_select_db on each action
Submitted2004-12-01 11:17 UTC
Fromandre dot steffens at adress-research dot de
StatusDuplicate
PackageDB
PHP Version4.3.9
OSWin2k
Roadmaps(Not assigned)

Comments

[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;
}
}

[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-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)