2010-06-12 4 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 
} 
?> 

당신은

SELECT * FROM database 

을 할 수없는 나에게

답변

7

도움말하지만 당신도

USE DATEBASE; 
SHOW TABLES; 

또는 더 잘 할 수주십시오

SHOW TABLES IN database 
+4

당신은 올바른 같은 @의 cherouvim의 답변을 선택해야합니다! – JonyD

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 
관련 문제