how to query all tables mysql at the same time

Solutions on MaxInterview for how to query all tables mysql at the same time by the best coders in the world

showing results for - "how to query all tables mysql at the same time"
Ashanti
08 Feb 2018
1function searchAllDB($search){
2    global $mysqli;
3
4    $out = "";
5
6    $sql = "show tables";
7    $rs = $mysqli->query($sql);
8    if($rs->num_rows > 0){
9        while($r = $rs->fetch_array()){
10            $table = $r[0];
11            $out .= $table.";";
12            $sql_search = "select * from ".$table." where ";
13            $sql_search_fields = Array();
14            $sql2 = "SHOW COLUMNS FROM ".$table;
15            $rs2 = $mysqli->query($sql2);
16            if($rs2->num_rows > 0){
17                while($r2 = $rs2->fetch_array()){
18                    $column = $r2[0];
19                    $sql_search_fields[] = $column." like('%".$search."%')";
20                }
21                $rs2->close();
22            }
23            $sql_search .= implode(" OR ", $sql_search_fields);
24            $rs3 = $mysqli->query($sql_search);
25            $out .= $rs3->num_rows."\n";
26            if($rs3->num_rows > 0){
27                $rs3->close();
28            }
29        }
30        $rs->close();
31    }
32
33    return $out;
34}
35
similar questions