 |
[PHP]
สอบถามเกี่ยวกับการจอย 2db หน่อยครับ ใช้ MySQL อะครับ |
|
 |
|
|
 |
 |
|
คือผมต้องการจอย 2 dp อะครับ
Code (PHP)
1. $connect1 = mysqli_connect( "localhost" , "db1" , "123456" , "db1" );
2. $connect2 = mysqli_connect( "localhost" , "db2" , "123456!" , "db2" );
3. $sql = "SELECT db1.member.username,db2.business.name
4. FROM db1.member
5. INNER JOIN db2.business ON db1.member.userid = db2.business.userid";
6. $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)
01. while ( $row = mysqli_fetch_array( $result ))
02. {
03.
04. echo '
05. <tr>
06. <td> '.$row["username"].' </td>
07. <td> '.$row["name"].' </td>
08.
09. </tr>
10. ';
11. }
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2021-08-25 11:24:59
|
 |
 |
 |
 |
Date :
2021-08-25 10:37:15 |
By :
pamchanok01 |
View :
814 |
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 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|