Home  >  Article  >  Backend Development  >  How to get mysql database table fields in PHP

How to get mysql database table fields in PHP

PHP中文网
PHP中文网Original
2017-03-23 10:22:461505browse

Connect via pdo by default

<?php
classShowTalbeColunms {
public static function showColunms($pdo,$colunmsName) {//判断传来的$pdo是否为pdo对象的实例化$b=is_a($pdo,&#39;PDO&#39;);
            if(!$b) {
                echo&#39;传来的对象不是PDO的实例化&#39;;
                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][&#39;Field&#39;];
                }
            }
            //打印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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php read and write filesNext article:php read and write files