Connect via pdo by default
<?php classShowTalbeColunms { public static function showColunms($pdo,$colunmsName) {//判断传来的$pdo是否为pdo对象的实例化$b=is_a($pdo,'PDO'); if(!$b) { echo'传来的对象不是PDO的实例化'; exit(); } $count = $pdo->query("SHOW FULL COLUMNS FROM ".$colunmsName); $arr=array(); //如果查询到结果if($count) { $arr=$count->fetchAll(); $colunms=array(); for ($i=0; $i < count($arr); $i++) { $colunms[$i]=$arr[$i]['Field']; } } //打印echo"<pre class="brush:php;toolbar:false">"; print_r($colunms); echo""; } } ?>
The above introduces the method of obtaining mysql database table fields in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.
Related articles:
php code to get all table names in the mysql database
PHP to get the implementation code of all tables in the MySQL database
php to get the mysql database version number mysql_get_server_info