|  | 
	                
  
    | 
	 
        สอบถามเกี่ยวกับการจอย 2db หน่อยครับ ใช้ MySQL อะครับ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | คือผมต้องการจอย 2 dp อะครับ 
 Code (PHP)
 
 $connect1 = mysqli_connect("localhost", "db1", "123456", "db1");
$connect2 = mysqli_connect("localhost", "db2", "123456!", "db2");
$sql = "SELECT db1.member.username,db2.business.name
FROM db1.member 
INNER JOIN db2.business ON db1.member.userid = db2.business.userid";  
$result = mysqli_query($connect2,$connect1,$sql);
 ตรง mysqli_query นี่ผมต้องเขียนแบบไหนเพื่อเชื่อม 2 db อะครับ เขียนยังงี้ มัน error  โค้ด sql ไม่ผิดพลาดครับเพราะเอาไปรันที่ mysql ก็ออกปกติ
 error :
 Code
 
 [25-Aug-2021 03:53:10 UTC] PHP Warning:  mysqli_query() expects parameter 2 to be string, object given in ... on line 10
[25-Aug-2021 03:53:10 UTC] PHP Warning:  mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in ... on line 41
 
 ถ้าเขียนแบบใช้แค่ db เดียว ข้อมูลมันก็ออกปกติครับ
 อันนี้โค้ดตรงรันข้อมูลออกมาครับ
 Code (PHP)
 
      while($row = mysqli_fetch_array($result))  
     {  
           
        echo '  
       <tr>  
         <td>'.$row["username"].'</td>  
         <td>'.$row["name"].'</td>  
       
                    </tr>
                     ';  
     }
 
 
 Tag : PHP, MySQL
 
 
 |  
            | 
 ประวัติการแก้ไข
 2021-08-25 11:24:59
 |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2021-08-25 10:37:15 | By :
                          pamchanok01 | View :
                          970 | Reply :
                          5 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
 
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | แบบนี้ไม่ถูกต้อง  $result = mysqli_query($connect2,$connect1,$sql); 
 ต้องแยกกัน
 
 $result1 = mysqli_query($connect1,$sql);
 $result2 = mysqli_query($connect2,$sql);
 
 
 ผมว่านะ ออกแบบใหม่ให้ db อันเดียวกันไหม
 
 |  
              | 
 ประวัติการแก้ไข
 2021-08-27 11:41:06
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2021-08-27 11:38:18 | By :
                            VsuperV |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | เปลี่ยน permission ของ user login ให้สามารถ ใช้งานได้ 2 database มันจะง่ายกว่าไหมครับ Code (SQL)
 
 
select t1.*, t2.*
from db1.tb_on_db1 t1 , db2.tb_on_db2 t2
where .....
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2021-08-28 11:06:43 | By :
                            Chaidhanan |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |