note 35017 added to function.mysql-select-db

From: Date: Fri, 15 Aug 2003 18:18:35 +0000
Subject: note 35017 added to function.mysql-select-db
Groups: php.notes 
Request: Send a blank email to php-notes+get-54226@lists.php.net to get a copy of this message
Something I found that is pretty amazing, and does not seem to be documented too well... If you want to perform a query on a different database, and have a mysql_select_db("database") already established for a different database, you can reference the other database like this: $db = mysql_connect("server","user","pass"); mysql_select_db("first_database"); $query_1 = mysql_query("SELECT name, password FROM table_in_first_database WHERE id = '$id'",$db); // Now we want to do something to another database: $query_2 = mysql_query("INSERT into database_2.visitor_log (date,ip,user) VALUES ('$date','$REMOTE_ADDR','$user')"); Note that you can reference database #2 by preceeding the table name with the database name. I did not know this and it will defnitely save some time by being able to reference a different database directly in the query. Dennis McEntire ---- Manual Page -- http://www.php.net/manual/en/function.mysql-select-db.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35017 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35017&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35017&report=yes

« previous php.notes (#54226) next »