|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-04-08 11:37 UTC] pgl at instinct dot 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 09:00:01 2025 UTC |
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); ?There is now 3rd optional parameter added to mysql_select_db() in CVS HEAD. This: $prev_dbname = mysql_select_db("new_db", $db, TRUE); returns the previous database name provided that you have selected some database before. (And not used "USE some_db" query to do that as was pointed by Markus in previous comments. --Jani