1<! Doctype html>234<meta http-equiv= "Content-type" content= "text/html; charset= "Utf-8"/>5 6 <body>7 <?php8 9 class Db_columnTen { Oneprotected static$db; Aprotected static function Initialdb ($dbName= ' mysql ') - { -if (!self::$db[$dbName]) the { - $servername= "localhost"; - $username= "Root"; - $password= ""; + //Create connection - $conn= New Mysqli ($servername,$username,$password,$dbName); +if ($conn->connect_error) { ADie ("Connection failed:".$conn->connect_error); at } -Self::$db[$dbName] =$conn; -Self::$db[$dbName]->query ("SET NAMES UTF8"); - } -Return self::$db[$dbName]; - } inpublic static function Getcolumncomment ($dbName,$table) - { to self::initialdb (' MySQL '); + $sql= "SELECT -* the from *Information_schema.COLUMNS $ WHEREPanax Notoginsengtable_name = ' $table ' and table_schema = ' $dbName ' "; - $result= Self::$db[' MySQL ']->query ($sql); theWhile$row=$result->fetch_assoc ()) { + $ret[] =$row; A } theReturn$ret; + } -public static function GetColumnInfo ($dbName,$table) $ { $SELF::INITIALDB ($dbName); - $sql= "Show Columns from$table"; - $result= Self::$db[$dbName]->query ($sql); theWhile$row=$result->fetch_assoc ()) { - $ret[] =$row;Wuyi } theReturn$ret; - } Wu } - About $ $columnInfo= Db_column::getcolumncomment ("DBA", "TBA"); - echo ' <table> '; - echo ' <tr> '; -foreach$columnInfoAs$col) A { + echo ' <th> '; theEcho$col["Column_comment"]; - echo ' </th> '; $ } the echo ' <tr> '; the echo ' </table> '; the ?> the </body> -Follow the table comments in MySQL to generate the table head class