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

How to get mysql database table fields in PHP

PHP中文网
Release: 2023-03-01 06:48:01
Original
1558 people have browsed it

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"
"; } } ?>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template