在PHP中选择多个数据库,但分别打印ID

时间:2019-06-09 14:12:17

标签: php

我想执行多个数据库选择,但是要分别打印ID。

$sql = "SELECT * FROM peron, peronmedia WHERE peronmedia.PID=5" and peron.ID=5"; $xc = mysqli_query($baglanti, $sql); $rs=mysqli_fetch_array($xc);

echo $rs["peron.PID"];
echo $rs["peronmedia.ID"];

但是此代码不起作用。 我该怎么办?

1 个答案:

答案 0 :(得分:0)

在表后定义别名是更好的理解方式,必须指定数据库名称,否则它将升高field list is ambiguous

$sql = "SELECT pr.PID AS PERON_PID,pm.ID AS PERONMEDIA_ID FROM peron pr, peronmedia pm WHERE databasename1.peronmedia.PID=5 AND databasename2.peron.ID=5"; 
$xc = mysqli_query($baglanti, $sql);
$rs=mysqli_fetch_array($xc);

echo $rs["PERON_PID"];
echo $rs["PERONMEDIA_ID"];