Bug #16495 Updated: Can mysql_select_db return the previously selected db?
| From: | pgl at instinct dot org | Date: | Fri, 26 Apr 2002 13:27:54 +0000 |
| Subject: | Bug #16495 Updated: Can mysql_select_db return the previously selected db? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-6104@lists.php.net to get a copy of this message | ||
ID: 16495
Updated by: pgl@instinct.org
Reported By: pgl@instinct.org
Status: Open
Bug Type: Feature/Change Request
Operating System: FreeBSD
PHP Version: 4.1.2
New Comment:
Would it be possible to add a flag to the end of the function call to
specify that you want it to return the name of the previously selected
db? eg:
$old_db_name = mysql_select_db('somedb', RETURN_OLD_DBNAME);
?
Previous Comments:
------------------------------------------------------------------------
[2002-04-08 11:55:20] pgl@instinct.org
True, but given that currently the only possible values the function
can return are TRUE or FALSE, it seems unlikely that anyone would
actually do that. Is there any other way to get the name of the current
db inside a function without using global?
------------------------------------------------------------------------
[2002-04-08 11:45:32] mfischer@php.net
Well, I can see.
If someone wrote
if (true === mysql_select_db( ...
it's broken (and the API has been long this way).
------------------------------------------------------------------------
[2002-04-08 11:37:30] pgl@instinct.org
Would it be possible for mysql_select_db() to return the previously
selected db on success, and false (as it does already) on failure? That
would make it more useful for times when you want to use another db
temporarily, eg:
function auth() {
// choose the auth db
$old_db_name = mysql_select_db('authdb');
// ... code to authenticate a user here ...
// change back to whatever was being used before
mysql_select_db($old_db_name);
}
I can't see how adding this would break any existing scripts, either,
as the returned value would still have to be true (you can't create
databases called '' in mysql, can you?).
regards,
Peter Lowe.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=16495&edit=1