Jump to content

select from multiple databases


project3

Recommended Posts

what I have is two tables in on table is the select box name.

in the other db is the options for the select boxes.

for some reason the cart is adding select box and some have no options.

 

what I want to do is make a select statement that will only select from select box db table

if it has options in the options table how do I go about that?

 

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/96030-select-from-multiple-databases/
Share on other sites

Try:

$conn = mysql_connect('localhost','username','password') or die (mysql_error());
$db1 = mysql_select_db("2nddatabasename",$conn) or die (mysql_error());
$db2 = mysql_select_db("1stdatabasename",$conn) or die (mysql_error());

You would then reference them as

mysql_query("SELECT `something` from `tablename` where `something`='1'",$db1) or die (mysql_error());

I've never had to do this, so I am presuming this is how it is done.

I'm assuming this is the right syntax:

 

$link = mysql_connect('host', 'user', 'pass');
$q = mysql_query("SELECT db1.table1.col1, db2.some_other_table.some_column FROM db1.table1, db2.some_other_table");

 

Obvioulsy that query would be useless, but hopefully you see the <db>.<table>.<column> syntax.  (Joins and stuff work with the same references I think.)

 

 

 

The only time I've actually selected from 2 databases was with MSSQL....  It was like this, so I would assume MYSQL has a similar syntax (and the capability x.x):

 

SELECT db1..table1.column1, db2..table2.column2 FROM db1..table1, db2..table2

 

(In MSSQL it's <db>.<user>.<table>.<column>)

I'm assuming this is the right syntax:

 

$link = mysql_connect('host', 'user', 'pass');
$q = mysql_query("SELECT db1.table1.col1, db2.some_other_table.some_column FROM db1.table1, db2.some_other_table");

 

Obvioulsy that query would be useless, but hopefully you see the <db>.<table>.<column> syntax.  (Joins and stuff work with the same references I think.)

 

 

 

The only time I've actually selected from 2 databases was with MSSQL....  It was like this, so I would assume MYSQL has a similar syntax (and the capability x.x):

 

SELECT db1..table1.column1, db2..table2.column2 FROM db1..table1, db2..table2

 

(In MSSQL it's <db>.<user>.<table>.<column>)

 

yes thats what i was going for. I got it to work thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.