dongwen1909 2014-10-08 15:32 采纳率: 0%
浏览 24
已采纳

mysqli PHP搜索和过滤MySQL中的两个数据库/表

I am trying to search and filter by two different databases.

DATABASE1.table1  |   DATABASE2.table1
id | col2         |   id | ref_col2 | ref_col3
1  | 2            |   1  | thing    | thing
2  | 500          |   2  | other    | other

I know you can use the following if its on the same database:

$search = explode(" ", mysqli_real_escape_string($connection, $_POST["search_string"]));
$search_string = " AND (";
for($i=0;$i<count($search);$i++){
    $search_string .= "(t2.ref_col2 LIKE '%".$search[$i]."%' OR t2.ref_col3 LIKE '%".$search[$i]."%') AND ";}
$search_string = substr($search_string,0,strlen($search_string)-4);
$search_string .= ")";  


$query = mysqli_query($connection, "SELECT t1.*, t2.* AS row_count FROM table1 AS t1 LEFT JOIN  table2 AS t2 ON t1.id = t2.id WHERE t1.id>0".$search_string)or die();

My question is: What if they are on two different databases? is there a specific way to select one database.table results by searching another database.table's list the above?

  • 写回答

1条回答 默认 最新

  • douyanning3724 2014-10-08 15:37
    关注

    if they are on the same server then

    database1.table1 AS t1 LEFT JOIN  database2.table2 AS t2 
    

    should be fine

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题