<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[PHP 生成数据字典]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[代码编程]]></category>
<pubDate>Wed, 14 Mar 2018 02:20:02 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	<div class="code"><br/>&lt;?php<br/>/**<br/> * 生成mysql数据字典<br/> */<br/>header(&quot;Content-type: text/html; charset=utf-8&quot;);<br/>//配置数据库<br/>$dbserver&nbsp;&nbsp; = &quot;127.0.0.1&quot;;<br/>$database&nbsp;&nbsp; = &quot;vuethink&quot;;<br/>$user = &#039;root&#039;;<br/>$password = &#039;root&#039;;<br/>//其他配置<br/>$dsn = &quot;mysql:dbname=$database;host=$dbserver&quot;;<br/><br/><br/>try &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$pdo = new PDO($dsn, $user, $password);<br/>&nbsp;&nbsp;&nbsp;&nbsp;$pdo-&gt;exec(&#039;SET NAMES utf8&#039;);<br/>&#125; catch (PDOException $e) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;Connection failed: &#039; . $e-&gt;getMessage();<br/>&#125;<br/><br/>$table_result = $pdo-&gt;query(&#039;show tables&#039;)-&gt;fetchAll();<br/><br/>$no_show_table = array();&nbsp;&nbsp;&nbsp;&nbsp;//不需要显示的表<br/>$no_show_field = array();&nbsp;&nbsp; //不需要显示的字段<br/><br/>//取得所有的表名<br/>foreach ($table_result as $row) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if(!in_array($row&#91;0&#93;,$no_show_table))&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tables&#91;&#93;&#91;&#039;TABLE_NAME&#039;&#93; = $row&#91;0&#93;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&#125;<br/><br/><br/>//替换所以表的表前缀<br/>if(@$_GET&#91;&#039;prefix&#039;&#93;)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$prefix = &#039;oa&#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;foreach($tables as $key =&gt; $val)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tableName = $val&#91;&#039;TABLE_NAME&#039;&#93;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$string = explode(&#039;_&#039;,$tableName);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($string&#91;0&#93; != $prefix)&#123;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$string&#91;0&#93; = $prefix;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$newTableName = implode(&#039;_&#039;, $string);&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysqli_query(&#039;rename table &#039;.$tableName.&#039; TO &#039;.$newTableName);&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;替换成功！&quot;;exit();<br/>&#125;<br/><br/>//循环取得所有表的备注及表中列消息<br/>foreach ($tables as $k=&gt;$v) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sql&nbsp;&nbsp;= &#039;SELECT * FROM &#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sql .= &#039;INFORMATION_SCHEMA.TABLES &#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sql .= &#039;WHERE &#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sql .= &quot;table_name = &#039;&#123;$v&#91;&#039;TABLE_NAME&#039;&#93;&#125;&#039;&nbsp;&nbsp;AND table_schema = &#039;&#123;$database&#125;&#039;&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$table_result = $pdo-&gt;query($sql)-&gt;fetchAll();<br/>&nbsp;&nbsp;&nbsp;&nbsp;foreach ($table_result as $t) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tables&#91;$k&#93;&#91;&#039;TABLE_COMMENT&#039;&#93; = $t&#91;&#039;TABLE_COMMENT&#039;&#93;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;$sql&nbsp;&nbsp;= &#039;SELECT * FROM &#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sql .= &#039;INFORMATION_SCHEMA.COLUMNS &#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sql .= &#039;WHERE &#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sql .= &quot;table_name = &#039;&#123;$v&#91;&#039;TABLE_NAME&#039;&#93;&#125;&#039; AND table_schema = &#039;&#123;$database&#125;&#039;&quot;;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;$fields = array();<br/>&nbsp;&nbsp;&nbsp;&nbsp;$field_result = $pdo-&gt;query($sql)-&gt;fetchAll();<br/>&nbsp;&nbsp;&nbsp;&nbsp;foreach ($field_result as $t) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$fields&#91;&#93; = $t;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$tables&#91;$k&#93;&#91;&#039;COLUMN&#039;&#93; = $fields;<br/>&#125;<br/><br/><br/><br/>$html = &#039;&#039;;<br/>//循环所有表<br/>foreach ($tables as $k=&gt;$v) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&lt;h3&gt;&#039; . ($k + 1) . &#039;、&#039; . $v&#91;&#039;TABLE_COMMENT&#039;&#93; .&#039;&nbsp;&nbsp;（&#039;. $v&#91;&#039;TABLE_NAME&#039;&#93;. &#039;）&lt;/h3&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot;&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tbody&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;th&gt;字段名&lt;/th&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;th&gt;数据类型&lt;/th&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;th&gt;默认值&lt;/th&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;th&gt;允许非空&lt;/th&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;th&gt;自动递增&lt;/th&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;th&gt;备注&lt;/th&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;&#039;.&quot;&#92;n&quot;;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;foreach ($v&#91;&#039;COLUMN&#039;&#93; as $f) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(@!is_array($no_show_field&#91;$v&#91;&#039;TABLE_NAME&#039;&#93;&#93;))&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$no_show_field&#91;$v&#91;&#039;TABLE_NAME&#039;&#93;&#93; = array();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!in_array($f&#91;&#039;COLUMN_NAME&#039;&#93;,$no_show_field&#91;$v&#91;&#039;TABLE_NAME&#039;&#93;&#93;))&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;c1&quot;&gt;&#039; . $f&#91;&#039;COLUMN_NAME&#039;&#93; . &#039;&lt;/td&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;c2&quot;&gt;&#039; . $f&#91;&#039;COLUMN_TYPE&#039;&#93; . &#039;&lt;/td&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;c3&quot;&gt;&#039; . $f&#91;&#039;COLUMN_DEFAULT&#039;&#93; . &#039;&lt;/td&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;c4&quot;&gt;&#039; . $f&#91;&#039;IS_NULLABLE&#039;&#93; . &#039;&lt;/td&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;c5&quot;&gt;&#039; . ($f&#91;&#039;EXTRA&#039;&#93;==&#039;auto_increment&#039;?&#039;是&#039;:&#039;&amp;nbsp;&#039;) . &#039;&lt;/td&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td class=&quot;c6&quot;&gt;&#039; . $f&#91;&#039;COLUMN_COMMENT&#039;&#93; . &#039;&lt;/td&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tbody&gt;&#039;.&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$html .= &#039;&nbsp;&nbsp;&lt;/table&gt;&#039;.&quot;&#92;n&quot;;<br/>&#125;<br/>?&gt;<br/>&lt;!doctype html&gt;<br/>&lt;html&gt;<br/>&lt;head&gt;<br/>&lt;meta charset=&quot;utf-8&quot;&gt;<br/>&lt;title&gt;数据库数据字典生成代码&lt;/title&gt;<br/>&lt;meta name=&quot;generator&quot; content=&quot;ThinkDb V1.0&quot; /&gt;<br/>&lt;meta name=&quot;author&quot; content=&quot;数据库数据字典生成代码&quot; /&gt;<br/>&lt;style&gt;<br/>body, td, th &#123; font-family: &quot;微软雅黑&quot;; font-size: 14px; &#125;<br/>.warp&#123;margin:auto; width:900px;&#125;<br/>.warp h3&#123;margin:0px; padding:0px; line-height:30px; margin-top:10px;&#125;<br/>table &#123; border-collapse: collapse; border: 1px solid #CCC; background: #efefef; &#125;<br/>table th &#123; text-align: left; font-weight: bold; height: 26px; line-height: 26px; font-size: 14px; text-align:center; border: 1px solid #CCC; padding:5px;&#125;<br/>table td &#123; height: 20px; font-size: 14px; border: 1px solid #CCC; background-color: #fff; padding:5px;&#125;<br/>.c1 &#123; width: 120px; &#125;<br/>.c2 &#123; width: 120px; &#125;<br/>.c3 &#123; width: 150px; &#125;<br/>.c4 &#123; width: 80px; text-align:center;&#125;<br/>.c5 &#123; width: 80px; text-align:center;&#125;<br/>.c6 &#123; width: 270px; &#125;<br/>&lt;/style&gt;<br/>&lt;/head&gt;<br/>&lt;body&gt;<br/>&lt;div class=&quot;warp&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1 style=&quot;text-align:center;&quot;&gt;数据库数据字典&lt;/h1&gt;<br/>&lt;?php echo $html; ?&gt;<br/>&lt;/div&gt;<br/>&lt;/body&gt;<br/>&lt;/html&gt;<br/></div>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] PHP 生成数据字典]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>