For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > July 2007 > RE: Best Practices? [PHP-DB] Queries from two databases









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: Best Practices? [PHP-DB] Queries from two databases
Instruct ICC

2007-07-19, 6:58 pm

>From: Joaquín <javalpi@gmail.com>
>I need query tables that are in two different databases
>mysql_select_db("DB1", $conn_1);
>
>mysql_select_db("DB2", $conn_2);
>
>$result_t1 = mysql_query("SELECT * FROM `Table1inDB1`",$conn_1);
>$row_t1 = mysql_fetch_assoc($result_t1);
>
>$result_t2 = mysql_query("SELECT * FROM `Table2inDB2`",$conn_2);
>$row_t2 = mysql_fetch_assoc($result_t2);


Although Joaquín said his issue is [Fixed], I write these queries as:
SELECT * FROM DB1.TableInDB1
SELECT * FROM DB2.TableInDB2
(with and without link_identifiers I believe), so I was wondering about best
practices.

I can see if you already have code written without the DB in the FROM
clause, it could be easier to have multiple links.

I haven't really used multiple links, but I ran into issues with multiple
databases and consistently setting the correct DB, so now if I know I'll be
using multiple DB's, I just write the query with the DB in the FROM clause.
(A prior fix was to select the DB before each query. But if it was already
selected, it seemed like a waste {according to my "by inspection" profiler}.
So I started using the DB in the FROM clause.)

Are there any recommendations regarding best practices between:
1) using multiple links and table.field (or table) notation
versus
2) database.table.field (or database.table) notation?

________________________________________
_________________________
Local listings, incredible imagery, and driving directions - all in one
place! http://maps.live.com/?wip=69&FORM=MGAC01
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com