从无法在linux cpanel上运行的不同数据库中选择两个或多个表

时间:2018-09-29 04:41:18

标签: php mysql mysqli

此查询适用于本地xampp:

SELECT t1.id, t1.name, t2.id, t2.telephone
FROM db1.table1 t1
INNER JOIN db2.table2 t2 on t1.id = t2.id;

但是同一查询在LINUX cPanel上不起作用

<?php 

    $hostname='localhost'; 
    $username='root'; 
    $password=''; 
    $db='smart_software'; 

    $username2='root'; 
    $password2=''; 
    $db2='smart_stationary'; 

    $con1 = mysqli_connect($hostname, $username, $password, $db); 
    $con2 = mysqli_connect($hostname, $username2, $password2, $db2);

    $result=mysqli_query($con2,"select MSC.mobile_sub_cat_id, MSC.employee_id, ED.employee_name, LN.location, MC.mobile_cat_name, MSC.service_provider, MSC.number FROM smart_stationary.mobile_sub_cat MSC LEFT JOIN smart_stationary.mobile_cat MC ON MC.mobile_cat_id=MSC.mobile_cat_id LEFT JOIN smart_software.employee_details ED ON ED.employee_id=MSC.employee_id LEFT JOIN smart_stationary.location LN ON LN.location_id=MSC.location_id"); 

    while($row=mysqli_fetch_array($result)) { 
        echo $row['location']; 
    } 
?>

1 个答案:

答案 0 :(得分:0)


-确定两个数据库都可以在mysql中访问

  1. 在cpanel phpmyadmin上创建用户。
  2. 设置权限