본문 바로가기

프로그래밍/PHP

모든 테이블의 컬럼정보를 가져오기 위한 코드

*유의사항

테이블이나 컬럼이 많을 경우 서버 과부화로 인해 Lock이 걸릴 수 있음 ( 복잡도 : 테이블 개수 * 컬럼 개수 )


#테이블명 가져오기 위한 쿼리

$query_table = db_query('SHOW TABLES');


#테이블명으로 반복문

while ( $result_table = db_fetch_assoc($query_table)){


echo "테이블명 : ".$result_table['Tables_in_DB명']."<br>";

#필드명을 가져오기 위한 쿼리

$sql_clumns = db_query('SHOW FULL COLUMNS FROM '.$result_table['Tables_in_champstudy']);


#필드명으로 반복문

while ( $result_clumns = db_fetch_assoc($sql_clumns)){

echo "필드명 : ".$result_clumns['Field']." // 코멘트: ".$result_clumns['Comment']."<br>";

}

echo "<br>";

}