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
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.

Link to comment
Share on other sites

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>)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.