简体   繁体   中英

Joining tables from two different databases

$db=mysql_connect("localhost", "testuser1", "testuser1") or die(mysql_error()); 
$db2=mysql_connect("localhost", "testuser2", "testuser2", true) or die(mysql_error()); 
$dbname="database1"; 
$dbname2="database2";

mysql_select_db($dbname,$db) or die (mysql_error());
mysql_select_db($dbname2,$db2) or die (mysql_error());


 //this is for the product attributes
 $data = mysql_query("SELECT db.attribute_stock, db.options_values_sku
                                 FROM db.products_attributes 
                                 LEFT OUTER JOIN db2.oscomstock ON db.product_attributes.options_value_sku=db2.oscomstock.options_value_sku 
                             ") or die(mysql_error()); 

However, when I try to do this I get the error:

SELECT command denied to user 'testuser2' for table 'products_attributes'

It appears to be only using one set of credentials for both databases when it does the sql query.

What do I need to do to get it to access with the correct credentials?

Thanks in advance.

There is definetely something wrong with your rights.

Go to the 'rights section' in your phpmyadmin, and find user 'testuser2' and edit his rights. Make sure every check box is ticked, click RUN and make sure 'testuser2' has 'all priveleges' now.

Hope this helps.

you need to grant access to both databases to one user. And connect to database server with that user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM