从两个不同的数据库连接表

时间:2022-04-04 09:51:07
$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.

在执行sql查询时,它似乎只对两个数据库使用一组凭据。

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

要使用正确的凭据访问它,我需要做什么?

Thanks in advance.

提前致谢。

2 个解决方案

#1


0  

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.

转到phpmyadmin中的“权限部分”,找到用户'testuser2'并编辑其权限。确保勾选每个复选框,单击RUN并确保'testuser2'现在具有'所有priveleges'。

Hope this helps.

希望这可以帮助。

#2


0  

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

您需要向两个用户授予对这两个数据库的访问权限。并与该用户连接到数据库服务器。

#1


0  

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.

转到phpmyadmin中的“权限部分”,找到用户'testuser2'并编辑其权限。确保勾选每个复选框,单击RUN并确保'testuser2'现在具有'所有priveleges'。

Hope this helps.

希望这可以帮助。

#2


0  

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

您需要向两个用户授予对这两个数据库的访问权限。并与该用户连接到数据库服务器。