码迷,mamicode.com
首页 > 数据库 > 详细

按照mysql的表注释来生成table head的class

时间:2015-04-12 01:14:43      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

 1 <!Doctype html>
 2 <html>
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset="utf-8" />
 5 </head>
 6 <body>
 7 <?php
 8 
 9 class db_column
10 {
11     protected static $db;
12     protected static function initialDB($dbName=‘mysql‘)
13     {
14         if(!self::$db[$dbName])
15         {
16             $servername = "localhost";
17             $username = "root";
18             $password = "";
19             // Create connection
20             $conn = new mysqli($servername, $username, $password,$dbName);
21             if ($conn->connect_error) {
22                 die("Connection failed: " . $conn->connect_error);
23             }
24             self::$db[$dbName] = $conn;
25             self::$db[$dbName]->query("SET NAMES UTF8");
26         }
27         return self::$db[$dbName];
28     }
29     public static function getColumnComment($dbName,$table)
30     {
31         self::initialDB(‘mysql‘);
32         $sql = "SELECT
33                 *
34                 FROM
35                 information_schema.COLUMNS
36                 WHERE
37                 TABLE_NAME = ‘$table‘ AND TABLE_SCHEMA = ‘$dbName‘";
38         $result = self::$db[‘mysql‘]->query($sql);
39         while($row = $result->fetch_assoc()) {
40             $ret[] = $row;
41         }
42         return $ret;
43     }
44     public static function getColumnInfo($dbName,$table)
45     {
46         self::initialDB($dbName);
47         $sql = "show columns from $table";
48         $result = self::$db[$dbName]->query($sql);
49         while($row = $result->fetch_assoc()) {
50             $ret[] = $row;
51         }
52             return $ret;
53     }
54 }
55 
56 
57 $columnInfo = db_column::getColumnComment("dba","tba");
58 echo ‘<table>‘;
59 echo ‘<tr>‘;
60 foreach($columnInfo as $col)
61 {
62     echo ‘<th>‘;
63     echo $col["COLUMN_COMMENT"];
64     echo ‘</th>‘;
65 }
66 echo ‘<tr>‘;
67 echo ‘</table>‘;
68 ?>
69 </body>
70 </html>

 

按照mysql的表注释来生成table head的class

标签:

原文地址:http://www.cnblogs.com/angular/p/4418848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!