2010-06-12 90 views
12

如何從mySql中的多個數據庫中選擇所有表格.. 我正在執行以下步驟,但無法實現目標。如何顯示來自多個數據庫的所有表格

<?php 
$a = "SHOW DATABASES"; 
$da = $wpdb->get_results($a); 

foreach($da as $k){ 
echo '<pre>'; 
print_r ($k->Database);//prints all the available databases 
echo '</pre>'; 
$nq = "USE $k->Database";//trying to select the individual database 
$newda = $wpdb->get_results($nq); 
$alld = "SELECT * FROM $k->Database"; 
$td = $wpdb->get_results($alld); 
var_dump($td);//returns empty array 
} 
?> 

請幫我

回答

7

你不能這樣做

SELECT * FROM database 

但你可以做

USE DATEBASE; 
SHOW TABLES; 

甚至更​​好:

SHOW TABLES IN database 
+4

您應該選擇@ cherouvim的答案正確的! – JonyD 2016-08-17 15:47:26

7

更妙的是:

顯示在一個SQL語句中的所有數據庫中的所有表(除了內部MySQL數據庫)。

SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql') 
0

mysql -e'select table_schema, table_name from information_schema.tables;'

這取決於你已具備了與以下內容的文件~/.my.cnf

[client] 
user=ADMINUSER  ## set user, usually 'root' 
password=PASSWORD ## set password 
相關問題