note 35017 rejected from function.mysql-select-db by didou
| From: | didou@php.net | Date: | Fri, 15 Aug 2003 19:28:07 +0000 |
| Subject: | note 35017 rejected from function.mysql-select-db by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54230@lists.php.net to get a copy of this message | ||
Note Submitter: dmcentire@pointclickngo.com
----
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