<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>火跃</title>
	<atom:link href="http://www.huoyue.org/feed" rel="self" type="application/rss+xml" />
	<link>http://www.huoyue.org</link>
	<description>专注于网站建设(PHP开发),网站优化(SEO),网站推广,网络营销</description>
	<lastBuildDate>Tue, 15 May 2012 15:59:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>dedecms在模板中显示联动选项</title>
		<link>http://www.huoyue.org/dedecms-enums</link>
		<comments>http://www.huoyue.org/dedecms-enums#comments</comments>
		<pubDate>Tue, 15 May 2012 15:59:03 +0000</pubDate>
		<dc:creator>火跃</dc:creator>
				<category><![CDATA[dedecms]]></category>
		<category><![CDATA[dedecms 模板]]></category>
		<category><![CDATA[dedecms 联动]]></category>

		<guid isPermaLink="false">http://www.huoyue.org/?p=437</guid>
		<description><![CDATA[我们在有时会在模板中调用联动，但是官方除了地区和信息分类的调用外，其它的都不能直接用标签调用。

其实调用很简单，代码如下：
<blockquote>&#60;input type='hidden' id='hidden_models' name='<strong>models</strong>'  value='0' /&#62;

&#60;span id='span_<strong>models</strong>' &#62;&#60;/span&#62;

&#60;span id='span_<strong>models</strong>_son'&#62;&#60;/span&#62;

&#60;span id='span_<strong>models</strong>_sec'&#62;&#60;/span&#62;

&#60;script language="javascript" type="text/javascript" src="/images/enums.js"&#62;&#60;/script&#62;

&#60;script language='javascript' type='text/javascript' src='/data/enums/<strong>models</strong>.js'&#62;&#60;/script&#62;

&#60;script language="javascript" type="text/javascript"&#62;MakeTopSelect("<strong>models</strong>", 0);  &#60;/script&#62;</blockquote>
其中 的models为联动名！]]></description>
		<wfw:commentRss>http://www.huoyue.org/dedecms-enums/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dedecms 模板制作技巧php和sql的使用</title>
		<link>http://www.huoyue.org/dedecms-templets-php</link>
		<comments>http://www.huoyue.org/dedecms-templets-php#comments</comments>
		<pubDate>Wed, 09 May 2012 03:58:50 +0000</pubDate>
		<dc:creator>火跃</dc:creator>
				<category><![CDATA[dedecms]]></category>
		<category><![CDATA[dedecms php]]></category>
		<category><![CDATA[dedecms 动态mqfh]]></category>
		<category><![CDATA[dedecms 模板]]></category>

		<guid isPermaLink="false">http://www.huoyue.org/?p=426</guid>
		<description><![CDATA[dedecms模板制作时，由于dedecms本身模板机制的问题，会带来很不方便。

今天在制作模板时发现一些不错的，在这儿记录一下！

内容页：

动态网址：首页网址加/plus/view.php?arcid=内容页ID

PHP变量：
<blockquote>{dede:php}
echo '&#60;pre&#62;';
print_r($arc-&#62;Fields);
echo '&#60;/pre&#62;';
echo $arc-&#62;Fields['title'];//标题
echo $arc-&#62;Fields['body'];//内容正文
echo $arc-&#62;Fields['typeid'];//所属栏目ID
echo $arc-&#62;Fields['typename'];//所属栏目名字
echo $arc-&#62;Fields['这儿填写你所需要的字段名就能得到相应的值'];
{/dede:php}</blockquote>
//上面代码生成的HTML文件里面无效

在内容页模板中加上上面代码就能找到你想的变量了

栏目页：

动态网址：首页网址加/plus/list.php?tid=栏目ID

PHP变量：
<blockquote>{dede:php}
echo '&#60;pre&#62;';
print_r($lv-&#62;Fields);
echo '&#60;/pre&#62;';
echo $ lv -&#62;Fields['title'];// 栏目名字
echo $ lv -&#62;Fields['id'];//栏目ID
echo $ lv -&#62;Fields['这儿填写你所需要的字段名就能得到相应的值'];
{/dede:php}</blockquote>
<span style="color: #ff0000;">模板中直接使用</span>
<span style="color: #ff0000;">{dede:field.array runphp='yes'}@me = (empty(@me['price']) ? "未知" : "{@me['price']}元/{@me['units']}"); {/dede:field.array}</span>
<span style="color: #ff0000;">模板DEDE标签内使用：</span>
<span style="color: #ff0000;">[field:array runphp='yes']@me = (empty(@me['price']) ? "未知" : "{@me['price']}元/{@me['units']}"); [/field:array]</span>

{dede:sql sql="SELECT * FROM dede_archives WHERE writer=<span style="color: #ff0000;">~writer~</span>"}
[field:id/],
{/dede:sql}
这个放到article_article.htm页面，将会检索出当前会员发布的相关文章，<span style="color: #ff0000;">这里的~ writer~会根据当前内容的环境变量进行替换后再执行查询</span>。
<span style="color: #ff0000;">这里出现在SQL语句中条件查询的~ writer~，也就是$arc-&#62;Fields这个里面的相关内容</span>

&#160;

DEDE标签中可以使用{dede:global.标签名/},只是要写成[field:global.标签名/] :

如"{dede:global.cfg_cmsurl/}"在DEDE标签内要写"[field:global.cfg_cmsurl/]"!

&#160;

附上内容和栏目数据库字段表：
<table style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #ddeda5; margin-bottom: 10px;" width="960" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#C1D1A3">
<tbody style="color: #666666;">
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" height="34">
<table style="font-size: 12px; color: #666666;" width="90%" border="0" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="29%"><strong>表名：dede_arctype</strong>
(ENGINE=MyISAM/CHARSET=gbk)</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="71%">说明：<span style="float: right;"><a style="color: #666666; text-decoration: none;" href="http://help.dedecms.com/dbdoc/v57/">Top</a></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="20%" height="28">字段名</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="28%">说明描述</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA">具体参数</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>id</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) unsigned NOT NULL auto_increment</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>reid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">上级栏目ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>topid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">顶级栏目ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>sortrank</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">排序</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) unsigned NOT NULL default '50'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>typename</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目名称</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(30) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>typedir</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目目录</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(60) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>isdefault</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">是否默认</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>defaultname</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">默认名称</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(15) NOT NULL default 'index.html'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>issend</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">是否支持投稿</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>channeltype</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目频道类型</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) default '1'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>maxpage</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">最大页面数</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '-1'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>ispart</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目属性</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>corank</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">浏览权限</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>tempindex</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">频道页模板</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(50) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>templist</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">列表页模板</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(50) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>temparticle</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">内容页模板</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(50) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>namerule</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">文章命名规则</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(50) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>namerule2</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">列表命名规则</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(50) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>modname</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">模型名称</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(20) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>description</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目描述</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(150) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>keywords</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目关键词</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(60) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>seotitle</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">SEO标题</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(80) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>moresite</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">多站点支持</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">tinyint(1) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>sitepath</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">站点根目录</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(60) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>siteurl</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">绑定域名</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(50) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>ishidden</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">是否隐藏</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>cross</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">交叉栏目</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">tinyint(1) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>crossid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">交叉ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">text</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>content</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目内容</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">text</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>smalltypes</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目小分类</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">text</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" bgcolor="#F7FDEA" height="28"><strong>索引：</strong>
PRIMARY KEY (`id`),
KEY `reid` (`reid`,`isdefault`,`channeltype`,`ispart`,`corank`,`topid`,`ishidden`),
KEY `sortrank` (`sortrank`)</td>
</tr>
</tbody>
</table>
&#160;

内容页：
<table style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #ddeda5; margin-bottom: 10px;" width="960" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#C1D1A3">
<tbody style="color: #666666;">
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" height="34">
<table style="font-size: 12px; color: #666666;" width="90%" border="0" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="29%"><strong>表名：dede_addonarticle</strong>
(ENGINE=MyISAM/CHARSET=gbk)</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="71%">说明：<span style="float: right;"><a style="color: #666666; text-decoration: none;" href="http://help.dedecms.com/dbdoc/v57/">Top</a></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="20%" height="28">字段名</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="28%">说明描述</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA">具体参数</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>aid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">文章ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumint(8) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>typeid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>body</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">内容</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumtext</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>redirecturl</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">跳转URL</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(255) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>templet</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">自定义模板</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(30) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>userip</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">用户IP</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(15) NOT NULL default ''</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" bgcolor="#F7FDEA" height="28"><strong>索引：</strong>
PRIMARY KEY (`aid`),
KEY `typeid` (`typeid`)</td>
</tr>
</tbody>
</table>
<table style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #ddeda5; margin-bottom: 10px;" width="960" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#C1D1A3">
<tbody style="color: #666666;">
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" height="34"><a name="dede_addonimages"></a>
<table style="font-size: 12px; color: #666666;" width="90%" border="0" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="29%"><strong>表名：dede_addonimages</strong>
(ENGINE=MyISAM/CHARSET=gbk)</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="71%">说明：<span style="float: right;"><a style="color: #666666; text-decoration: none;" href="http://help.dedecms.com/dbdoc/v57/">Top</a></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="20%" height="28">字段名</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="28%">说明描述</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA">具体参数</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>aid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">图集ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumint(8) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>typeid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>pagestyle</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">显示列表样式</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '1'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>maxwidth</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">最大宽度</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '600'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>imgurls</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">图片地址</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">text</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>row</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">行数</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>col</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">列数</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>isrm</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">特殊选项（下载远程图片、从ZIP压缩包中解压图片、网上复制图片)</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>ddmaxwidth</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">缩略图最大宽度</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '200'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>pagepicnum</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">每页显示图片数量</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '12'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>templet</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">自定义模板</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(30) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>userip</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">用户IP</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(15) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>redirecturl</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">跳转地址</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(255) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>body</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">图集详细说明</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumtext</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" bgcolor="#F7FDEA" height="28"><strong>索引：</strong>
PRIMARY KEY (`aid`),
KEY `imagesMain` (`typeid`)</td>
</tr>
</tbody>
</table>
<table style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #ddeda5; margin-bottom: 10px;" width="960" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#C1D1A3">
<tbody style="color: #666666;">
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" height="34"><a name="dede_addoninfos"></a>
<table style="font-size: 12px; color: #666666;" width="90%" border="0" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="29%"><strong>表名：dede_addoninfos</strong>
(ENGINE=MyISAM/CHARSET=gbk)</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="71%">说明：<span style="float: right;"><a style="color: #666666; text-decoration: none;" href="http://help.dedecms.com/dbdoc/v57/">Top</a></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="20%" height="28">字段名</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="28%">说明描述</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA">具体参数</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>aid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">内容ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">int(11) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>typeid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">int(11) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>channel</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">频道类型</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>arcrank</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">内容排序</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(6) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>mid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">会员ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumint(8) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>click</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">点击次数</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">int(10) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>title</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">标题</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(60) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>litpic</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">缩略图</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(60) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>userip</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">用户IP</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(15) NOT NULL default ' '</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>senddate</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">发布时间</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">int(11) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>flag</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">属性</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">set('c','h','p','f','s','j','a','b') default NULL</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>lastpost</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">最后回复</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">int(10) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>scores</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">分数</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumint(8) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>goodpost</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">好评</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumint(8) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>badpost</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">差评</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumint(8) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>nativeplace</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">联动,地址</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>infotype</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">信息类型</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(20) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>body</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">内容</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumtext</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>endtime</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">结束时间</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">int(11) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>tel</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">电话号码</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(50) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>email</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">电子邮箱</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(50) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>address</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">地址</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(100) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>linkman</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">联系人</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(50) NOT NULL default ''</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" bgcolor="#F7FDEA" height="28"><strong>索引：</strong>
PRIMARY KEY (`aid`),
KEY `typeid` (`typeid`,`nativeplace`,`infotype`),
KEY `channel` (`channel`,`arcrank`,`mid`,`click`,`title`,`litpic`,`senddate`,`flag`,`endtime`)</td>
</tr>
</tbody>
</table>
<table style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #ddeda5; margin-bottom: 10px;" width="960" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#C1D1A3">
<tbody style="color: #666666;">
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" height="34"><a name="dede_addonshop"></a>
<table style="font-size: 12px; color: #666666;" width="90%" border="0" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="29%"><strong>表名：dede_addonshop</strong>
(ENGINE=MyISAM/CHARSET=gbk)</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="71%">说明：<span style="float: right;"><a style="color: #666666; text-decoration: none;" href="http://help.dedecms.com/dbdoc/v57/">Top</a></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="20%" height="28">字段名</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="28%">说明描述</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA">具体参数</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>aid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">内容ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumint(8) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>typeid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>body</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">商品简介</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumtext</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>price</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">市场价</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">float NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>trueprice</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">优惠价</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">float NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>brand</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">品牌</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(250) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>units</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">计量单位</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(250) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>templet</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">自定义模板</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(30) NOT NULL</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>userip</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">用户ip</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(15) NOT NULL</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>redirecturl</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">跳转地址</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(255) NOT NULL</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>vocation</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(20) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>infotype</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(20) NOT NULL default '0'</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" bgcolor="#F7FDEA" height="28"><strong>索引：</strong>
PRIMARY KEY (`aid`),
KEY `typeid` (`typeid`)</td>
</tr>
</tbody>
</table>
<table style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #ddeda5; margin-bottom: 10px;" width="960" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#C1D1A3">
<tbody style="color: #666666;">
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" height="34"><a name="dede_addonsoft"></a>
<table style="font-size: 12px; color: #666666;" width="90%" border="0" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="29%"><strong>表名：dede_addonsoft</strong>
(ENGINE=MyISAM/CHARSET=gbk)</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" width="71%">说明：<span style="float: right;"><a style="color: #666666; text-decoration: none;" href="http://help.dedecms.com/dbdoc/v57/">Top</a></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="20%" height="28">字段名</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA" width="28%">说明描述</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" bgcolor="#F7FDEA">具体参数</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>aid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">内容ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumint(8) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>typeid</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">栏目ID</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>filetype</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">文件类型</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(10) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>language</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">语言</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(10) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>softtype</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">软件类别</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(10) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>accredit</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">授权方式</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(10) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>os</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">操作系统</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(30) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>softrank</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">文章排序</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">mediumint(8) unsigned NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>officialUrl</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">官方网址</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(30) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>officialDemo</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">演示网址</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(50) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>softsize</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">软件大小</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(10) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>softlinks</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">软件地址</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">text</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>introduce</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">详细介绍</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">text</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>daccess</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">下载级别</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>needmoney</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">需要金币</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">smallint(5) NOT NULL default '0'</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>templet</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">自定义模板</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(30) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>userip</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">用户IP</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">char(15) NOT NULL default ''</td>
</tr>
<tr bgcolor="#FFFFFF">
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;"><strong>redirecturl</strong></td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">跳转地址</td>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;">varchar(255) NOT NULL default ''</td>
</tr>
<tr>
<td style="font-size: 12px; font-family: Arial, 宋休, 'Courier New'; color: #666666;" colspan="3" bgcolor="#F7FDEA" height="28"><strong>索引：</strong>
PRIMARY KEY (`aid`),
KEY `softMain` (`typeid`)</td>
</tr>
</tbody>
</table>]]></description>
		<wfw:commentRss>http://www.huoyue.org/dedecms-templets-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dedecms 模板使用技巧</title>
		<link>http://www.huoyue.org/dedecms-templets-help</link>
		<comments>http://www.huoyue.org/dedecms-templets-help#comments</comments>
		<pubDate>Tue, 08 May 2012 08:26:44 +0000</pubDate>
		<dc:creator>火跃</dc:creator>
				<category><![CDATA[dedecms]]></category>
		<category><![CDATA[dedecms if]]></category>
		<category><![CDATA[dedecms 缩略图]]></category>

		<guid isPermaLink="false">http://www.huoyue.org/?p=424</guid>
		<description><![CDATA[这几天在制作DEDECMS模板时，遇到一些问题，发现一些技巧，在这里记录一下！
<ul>
	<li>判断是否有缩略图，有就添加说明；</li>
</ul>
<blockquote>{dede:list pagesize='40' titlelen='56'}
&#60;li&#62;
&#60;a href="[field:arcurl/]"&#62;[field:array runphp='yes']@me = (strpos(@me['litpic'],'defaultpic') ? "" : '【图】'); [/field:array][field:title/]&#60;/a&#62;
&#60;/li&#62;
{/dede:list}</blockquote>
<ul>
	<li>内容页使用if判断：</li>
</ul>
<blockquote>{dede:field.price runphp='yes'}
if(@me&#60;&#62;'')@me=@me."元";
else
@me="商议";
{/dede:field.price}</blockquote>
<ul>
	<li>首页调用内容模块附表的字段：</li>
</ul>
<blockquote>{dede:arclist  <span style="color: #ff0000;">addfields='trueprice,price'</span>  <strong><span style="color: #000000;">channelid='6' </span></strong>  typeid=8 row=10  orderby='pubdate' }
本站价格:<span style="color: #ff0000;">[field:trueprice/]</span>
市场价格:<span style="color: #ff0000;">[field:price/]</span>
{/dede:arclist}

<strong>注：途中红色标记的地方请根据自己的情况更改！channelid='6' 必须加上！
</strong></blockquote>]]></description>
		<wfw:commentRss>http://www.huoyue.org/dedecms-templets-help/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript 回车事件</title>
		<link>http://www.huoyue.org/javascript-enter</link>
		<comments>http://www.huoyue.org/javascript-enter#comments</comments>
		<pubDate>Tue, 27 Mar 2012 09:23:52 +0000</pubDate>
		<dc:creator>火跃</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[回车]]></category>
		<category><![CDATA[回车提交]]></category>

		<guid isPermaLink="false">http://www.huoyue.org/?p=421</guid>
		<description><![CDATA[很多地方要用到回车事件，今天发现 一个新的方法，在这记录一下.

js代码：
<blockquote>function isenter(e) {

var kCode = String.fromCharCode(e.keyCode);

if(kCode == "\n" &#124;&#124; kCode == "\r")

alert('你按下了回车');

}

&#160;</blockquote>
html代码：
<blockquote>&#60;input type='text'   onkeypress=" isenter(event);" /&#62;</blockquote>
完成。]]></description>
		<wfw:commentRss>http://www.huoyue.org/javascript-enter/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>百度自动ping功能javascript和php代码</title>
		<link>http://www.huoyue.org/baidu-ping-javascript-php-code</link>
		<comments>http://www.huoyue.org/baidu-ping-javascript-php-code#comments</comments>
		<pubDate>Mon, 27 Feb 2012 06:23:28 +0000</pubDate>
		<dc:creator>火跃</dc:creator>
				<category><![CDATA[PHP+mysql]]></category>

		<guid isPermaLink="false">http://www.huoyue.org/?p=415</guid>
		<description><![CDATA[百度自动ping功能对SEO有不少帮助，在这收藏一下百度官方页的javascript代码和PHP代码.

百度官方的ping功能javascript代码：

&#160;
<blockquote>&#60;script&#62;

 function pin(url,value){
  var request = null;
   try{
    var request=new XMLHttpRequest();
   }
   catch(e){}
   if(request==null) try {
    request = new ActiveXObject("Microsoft.XMLHTTP");
   }catch (e) {}
   if(request==null) try {
    request=new ActiveXObject("MSXML2.XMLHTTP.3.0");
    }catch (e) {}
   if(request==null) try {
   request=new ActiveXObject("Msxml2.XMLHTTP");
   }catch (e) {}
 
     var values="&#60;?xml version=\"1.0\"?&#62;\n&#60;methodCall&#62;\n&#60;methodName&#62;weblogUpdates.ping&#60;/methodName&#62;\n&#60;params&#62;\n&#60;param&#62;\n&#60;value&#62;&#60;string&#62;"+value+"&#60;/string&#62;&#60;/value&#62;\n&#60;/param&#62;&#60;param&#62;&#60;value&#62;&#60;string&#62;"+value+"&#60;/string&#62;&#60;/value&#62;\n&#60;/param&#62;\n&#60;/params&#62;\n&#60;/methodCall&#62;";
  
  request.onreadystatechange = function(){
    if (request.readyState == 4) {
             if (request.status == 200) {
                 
   document.getElementById("alert1").style.display="none";
   document.getElementById("alert2").style.display="inline";
   document.getElementById("alert3").style.display="none";
   
              }
              else {
               
   document.getElementById("alert1").style.display="none";
   document.getElementById("alert2").style.display="none";
   document.getElementById("alert3").style.display="inline"; 
   
             }
          }
  }
  
  request.open("POST", url);
  request.setRequestHeader("Content-Type", "text/xml");
  request.send(values);
 }
 function check_form(){
  
  var sUrl=document.getElementById("url");
  
  if(sUrl.value=="" &#124;&#124; sUrl.value=="http://"){
   document.getElementById("alert1").style.display="inline";
   document.getElementById("alert2").style.display="none";
   document.getElementById("alert3").style.display="none";

  }else{
   pin("/ping/RPC2",sUrl.value); 
  }
 }
&#60;/script&#62;

&#160;</blockquote>
PHP代码为：
<blockquote>&#60;?php
function postUrl($url, $postvar)
{
    $ch = curl_init();
    $headers = array(
        "POST ".$url." HTTP/1.0",
        "Content-type: text/xml; charset=\"utf-8\"",
        "Accept: text/xml",
        "Content-length: ".strlen($postvar)
    );
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postvar);
    $res = curl_exec ($ch);
    curl_close ($ch);
    return $res;
}

$baiduXML = "&#60;?xml version=\"1.0\" encoding=\"utf-8\"?&#62;
   &#60;methodCall&#62;
   &#60;methodName&#62;weblogUpdates.extendedPing&#60;/methodName&#62;
   &#60;params&#62;
   &#60;param&#62;&#60;value&#62;&#60;string&#62;$url&#60;/string&#62;&#60;/value&#62;&#60;/param&#62;
   &#60;param&#62;&#60;value&#62;&#60;string&#62;$url&#60;/string&#62;&#60;/value&#62;&#60;/param&#62;
   &#60;/params&#62;
   &#60;/methodCall&#62;";
$res = postUrl('http://ping.baidu.com/ping/RPC2', $baiduXML);
?&#62;</blockquote>]]></description>
		<wfw:commentRss>http://www.huoyue.org/baidu-ping-javascript-php-code/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP超大文件下载，断点续传下载</title>
		<link>http://www.huoyue.org/php-big-file-down</link>
		<comments>http://www.huoyue.org/php-big-file-down#comments</comments>
		<pubDate>Thu, 16 Feb 2012 13:07:03 +0000</pubDate>
		<dc:creator>火跃</dc:creator>
				<category><![CDATA[PHP+mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[断点续传下载]]></category>
		<category><![CDATA[超大文件下载]]></category>

		<guid isPermaLink="false">http://www.huoyue.org/?p=409</guid>
		<description><![CDATA[<span style="background-color: #ffffff; font-family: Verdana, 'BitStream vera Sans', Helvetica, sans-serif; font-size: 12px; line-height: 18px;">　　最近公司导出订单信息的时候出现一个php</span><span style="background-color: #ffffff; font-family: Verdana, 'BitStream vera Sans', Helvetica, sans-serif; font-size: 12px; line-height: 18px;">内存溢出的问题，原因就是在于下载的</span><span style="background-color: #ffffff; font-family: Verdana, 'BitStream vera Sans', Helvetica, sans-serif; font-size: 12px; line-height: 18px;">时候读取生成的临时文件过大，PHP内存无法容纳，一开如是想到更改PHP内存限制，但是这个只是一个缓兵之计，于是想到了另外一个方法是把文件分次读取，并下载。</span>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; font-family: Verdana, 'BitStream vera Sans', Helvetica, sans-serif; font-size: 12px; line-height: 18px; background-color: #ffffff; padding: 0px;">以下是源代码：<span style="color: #006699; padding: 0px; margin: 0px;"><strong style="padding: 0px; margin: 0px;"><br style="padding: 0px; margin: 0px;" /></strong></span></p>

<ol class="dp-c" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 50px; border-left-width: 3px; border-left-style: solid; border-left-color: #146b00; padding: 0px;">
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span style="padding: 0px; margin: 0px;">&#60;?php  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$sourceFile</span><span style="padding: 0px; margin: 0px;"> = </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"1.tmp"</span><span style="padding: 0px; margin: 0px;">; </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//要下载的临时文件名 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">  </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$outFile</span><span style="padding: 0px; margin: 0px;"> = </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"用户订单.xls"</span><span style="padding: 0px; margin: 0px;">; </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//下载保存到客户端的文件名 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">  </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$file_extension</span><span style="padding: 0px; margin: 0px;"> = </span><span class="func" style="padding: 0px; margin: 0px;">strtolower</span><span style="padding: 0px; margin: 0px;">(</span><span class="func" style="padding: 0px; margin: 0px;">substr</span><span style="padding: 0px; margin: 0px;">(</span><span class="func" style="padding: 0px; margin: 0px;">strrchr</span><span style="padding: 0px; margin: 0px;">(</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$sourceFile</span><span style="padding: 0px; margin: 0px;">, </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"."</span><span style="padding: 0px; margin: 0px;">), 1)); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//获取文件扩展名 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">//echo $sourceFile; </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="keyword" style="color: blue; padding: 0px; margin: 0px;">if</span><span style="padding: 0px; margin: 0px;"> (!</span><span class="func" style="padding: 0px; margin: 0px;">ereg</span><span style="padding: 0px; margin: 0px;">(</span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"[tmp&#124;txt&#124;rar&#124;pdf&#124;doc]"</span><span style="padding: 0px; margin: 0px;">, </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$file_extension</span><span style="padding: 0px; margin: 0px;">))</span><span class="func" style="padding: 0px; margin: 0px;">exit</span><span style="padding: 0px; margin: 0px;"> (</span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"非法资源下载"</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">  </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">//检测文件是否存在 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="keyword" style="color: blue; padding: 0px; margin: 0px;">if</span><span style="padding: 0px; margin: 0px;"> (!</span><span class="func" style="padding: 0px; margin: 0px;">is_file</span><span style="padding: 0px; margin: 0px;">(</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$sourceFile</span><span style="padding: 0px; margin: 0px;">)) {  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">die</span><span style="padding: 0px; margin: 0px;">(</span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"&#60;b&#62;404 File not found!&#60;/b&#62;"</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">}  </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">  </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$len</span><span style="padding: 0px; margin: 0px;"> = </span><span class="func" style="padding: 0px; margin: 0px;">filesize</span><span style="padding: 0px; margin: 0px;">(</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$sourceFile</span><span style="padding: 0px; margin: 0px;">); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//获取文件大小 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$filename</span><span style="padding: 0px; margin: 0px;"> = </span><span class="func" style="padding: 0px; margin: 0px;">basename</span><span style="padding: 0px; margin: 0px;">(</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$sourceFile</span><span style="padding: 0px; margin: 0px;">); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//获取文件名字 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$outFile_extension</span><span style="padding: 0px; margin: 0px;"> = </span><span class="func" style="padding: 0px; margin: 0px;">strtolower</span><span style="padding: 0px; margin: 0px;">(</span><span class="func" style="padding: 0px; margin: 0px;">substr</span><span style="padding: 0px; margin: 0px;">(</span><span class="func" style="padding: 0px; margin: 0px;">strrchr</span><span style="padding: 0px; margin: 0px;">(</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$outFile</span><span style="padding: 0px; margin: 0px;">, </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"."</span><span style="padding: 0px; margin: 0px;">), 1)); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//获取文件扩展名 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">  </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">//根据扩展名 指出输出浏览器格式 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="keyword" style="color: blue; padding: 0px; margin: 0px;">switch</span><span style="padding: 0px; margin: 0px;"> (</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$outFile_extension</span><span style="padding: 0px; margin: 0px;">) {  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">case</span><span style="padding: 0px; margin: 0px;"> </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"exe"</span><span style="padding: 0px; margin: 0px;"> :  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$ctype</span><span style="padding: 0px; margin: 0px;"> = </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"application/octet-stream"</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">break</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">case</span><span style="padding: 0px; margin: 0px;"> </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"zip"</span><span style="padding: 0px; margin: 0px;"> :  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$ctype</span><span style="padding: 0px; margin: 0px;"> = </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"application/zip"</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">break</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">case</span><span style="padding: 0px; margin: 0px;"> </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"mp3"</span><span style="padding: 0px; margin: 0px;"> :  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$ctype</span><span style="padding: 0px; margin: 0px;"> = </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"audio/mpeg"</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">break</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">case</span><span style="padding: 0px; margin: 0px;"> </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"mpg"</span><span style="padding: 0px; margin: 0px;"> :  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$ctype</span><span style="padding: 0px; margin: 0px;"> = </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"video/mpeg"</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">break</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">case</span><span style="padding: 0px; margin: 0px;"> </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"avi"</span><span style="padding: 0px; margin: 0px;"> :  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$ctype</span><span style="padding: 0px; margin: 0px;"> = </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"video/x-msvideo"</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">break</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">default</span><span style="padding: 0px; margin: 0px;"> :  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">        <span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$ctype</span><span style="padding: 0px; margin: 0px;"> = </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"application/force-download"</span><span style="padding: 0px; margin: 0px;">;  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">}  </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">//Begin writing headers </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">header(<span class="string" style="color: blue; padding: 0px; margin: 0px;">"Cache-Control:"</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">header(<span class="string" style="color: blue; padding: 0px; margin: 0px;">"Cache-Control: public"</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">  </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">//设置输出浏览器格式 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">header(<span class="string" style="color: blue; padding: 0px; margin: 0px;">"Content-Type: $ctype"</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">header(<span class="string" style="color: blue; padding: 0px; margin: 0px;">"Content-Disposition: attachment; filename="</span><span style="padding: 0px; margin: 0px;"> . </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$outFile</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">header(<span class="string" style="color: blue; padding: 0px; margin: 0px;">"Accept-Ranges: bytes"</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">  </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$size</span><span style="padding: 0px; margin: 0px;"> = </span><span class="func" style="padding: 0px; margin: 0px;">filesize</span><span style="padding: 0px; margin: 0px;">(</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$sourceFile</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">  </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">//如果有$_SERVER['HTTP_RANGE']参数 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="keyword" style="color: blue; padding: 0px; margin: 0px;">if</span><span style="padding: 0px; margin: 0px;"> (isset (</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$_SERVER</span><span style="padding: 0px; margin: 0px;">[</span><span class="string" style="color: blue; padding: 0px; margin: 0px;">'HTTP_RANGE'</span><span style="padding: 0px; margin: 0px;">])) {  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="comment" style="color: green; padding: 0px; margin: 0px;">/*Range头域 　　Range头域可以请求实体的一个或者多个子范围。 </span> </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">    例如， </span> </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">    表示头500个字节：bytes=0-499 </span> </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">    表示第二个500字节：bytes=500-999 </span> </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">    表示最后500个字节：bytes=-500 </span> </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">    表示500字节以后的范围：bytes=500- 　　 </span> </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">    第一个和最后一个字节：bytes=0-0,-1 　　 </span> </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">    同时指定几个范围：bytes=500-600,601-999 　　 </span> </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">    但是服务器以忽略此请求头，如果无条件GET包含Range请求头，响应会以状态码206（PartialContent）返回而不是以200 （OK）。 </span> </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">    */</span><span style="padding: 0px; margin: 0px;">  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="comment" style="color: green; padding: 0px; margin: 0px;">// 断点后再次连接 $_SERVER['HTTP_RANGE'] 的值 bytes=4390912- </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    list (<span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$a</span><span style="padding: 0px; margin: 0px;">, </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$range</span><span style="padding: 0px; margin: 0px;">) = </span><span class="func" style="padding: 0px; margin: 0px;">explode</span><span style="padding: 0px; margin: 0px;">(</span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"="</span><span style="padding: 0px; margin: 0px;">, </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$_SERVER</span><span style="padding: 0px; margin: 0px;">[</span><span class="string" style="color: blue; padding: 0px; margin: 0px;">'HTTP_RANGE'</span><span style="padding: 0px; margin: 0px;">]);  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="comment" style="color: green; padding: 0px; margin: 0px;">//if yes, download missing part </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="func" style="padding: 0px; margin: 0px;">str_replace</span><span style="padding: 0px; margin: 0px;">(</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$range</span><span style="padding: 0px; margin: 0px;">, </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"-"</span><span style="padding: 0px; margin: 0px;">, </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$range</span><span style="padding: 0px; margin: 0px;">); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//这句干什么的呢。。。。 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$size2</span><span style="padding: 0px; margin: 0px;"> = </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$size</span><span style="padding: 0px; margin: 0px;"> -1; </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//文件总字节数 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$new_length</span><span style="padding: 0px; margin: 0px;"> = </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$size2</span><span style="padding: 0px; margin: 0px;"> - </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$range</span><span style="padding: 0px; margin: 0px;">; </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//获取下次下载的长度 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    header(<span class="string" style="color: blue; padding: 0px; margin: 0px;">"HTTP/1.1 206 Partial Content"</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    header(<span class="string" style="color: blue; padding: 0px; margin: 0px;">"Content-Length: $new_length"</span><span style="padding: 0px; margin: 0px;">); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//输入总长 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    header(<span class="string" style="color: blue; padding: 0px; margin: 0px;">"Content-Range: bytes $range$size2/$size"</span><span style="padding: 0px; margin: 0px;">); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//Content-Range: bytes 4908618-4988927/4988928   95%的时候 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">} <span class="keyword" style="color: blue; padding: 0px; margin: 0px;">else</span><span style="padding: 0px; margin: 0px;"> {  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="comment" style="color: green; padding: 0px; margin: 0px;">//第一次连接 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$size2</span><span style="padding: 0px; margin: 0px;"> = </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$size</span><span style="padding: 0px; margin: 0px;"> -1;  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    header(<span class="string" style="color: blue; padding: 0px; margin: 0px;">"Content-Range: bytes 0-$size2/$size"</span><span style="padding: 0px; margin: 0px;">); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//Content-Range: bytes 0-4988927/4988928 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    header(<span class="string" style="color: blue; padding: 0px; margin: 0px;">"Content-Length: "</span><span style="padding: 0px; margin: 0px;"> . </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$size</span><span style="padding: 0px; margin: 0px;">); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//输出总长 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">}  </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">//打开文件 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$fp</span><span style="padding: 0px; margin: 0px;"> = </span><span class="func" style="padding: 0px; margin: 0px;">fopen</span><span style="padding: 0px; margin: 0px;">(</span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"$sourceFile"</span><span style="padding: 0px; margin: 0px;">, </span><span class="string" style="color: blue; padding: 0px; margin: 0px;">"rb"</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">//设置指针位置 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="func" style="padding: 0px; margin: 0px;">fseek</span><span style="padding: 0px; margin: 0px;">(</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$fp</span><span style="padding: 0px; margin: 0px;">, </span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$range</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="comment" style="color: green; padding: 0px; margin: 0px;">//虚幻输出 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="keyword" style="color: blue; padding: 0px; margin: 0px;">while</span><span style="padding: 0px; margin: 0px;"> (!</span><span class="func" style="padding: 0px; margin: 0px;">feof</span><span style="padding: 0px; margin: 0px;">(</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$fp</span><span style="padding: 0px; margin: 0px;">)) {  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="comment" style="color: green; padding: 0px; margin: 0px;">//设置文件最长执行时间 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    set_time_limit(0);  </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    print (<span class="func" style="padding: 0px; margin: 0px;">fread</span><span style="padding: 0px; margin: 0px;">(</span><span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$fp</span><span style="padding: 0px; margin: 0px;">, 1024 * 8)); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//输出文件 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    <span class="func" style="padding: 0px; margin: 0px;">flush</span><span style="padding: 0px; margin: 0px;">(); </span><span class="comment" style="color: green; padding: 0px; margin: 0px;">//输出缓冲 </span><span style="padding: 0px; margin: 0px;"> </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">    ob_flush();  </span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">}  </span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">fclose(<span class="vars" style="color: #dd0000; padding: 0px; margin: 0px;">$fp</span><span style="padding: 0px; margin: 0px;">);  </span></span></li>
	<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;"><span class="func" style="padding: 0px; margin: 0px;">exit</span><span style="padding: 0px; margin: 0px;"> ();  </span></span></li>
	<li class="alt" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 5px; list-style-position: outside; margin: 0px;"><span style="padding: 0px; margin: 0px;">?&#62;  </span></li>
</ol>
&#160;

<a href="http://www.joyphper.net/article/201109/134.html">PHP超大文件下载，断点续传下载 - 大友博客-PHP爱好者</a>.]]></description>
		<wfw:commentRss>http://www.huoyue.org/php-big-file-down/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>二十种实战调优MySQL性能优化的经验</title>
		<link>http://www.huoyue.org/mysql-optimization</link>
		<comments>http://www.huoyue.org/mysql-optimization#comments</comments>
		<pubDate>Thu, 16 Feb 2012 01:29:10 +0000</pubDate>
		<dc:creator>火跃</dc:creator>
				<category><![CDATA[PHP+mysql]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL性能优化]]></category>
		<category><![CDATA[性能优化]]></category>

		<guid isPermaLink="false">http://www.huoyue.org/?p=405</guid>
		<description><![CDATA[<span style="background-color: #ffffff; color: #4d4b4c; font-family: Arial; line-height: 18px;">本文将为大家介绍的是二十条MySQL性能优化的经验，这些小经验有助于大家更好的使用MySQL进行WEB开发。今天，数据库的操作越来越成为整个应用的性能瓶颈了，这点对于Web应用尤其明显。关于数据库的性能，这并不只是DBA才需要担心的事，而这更是我们程序员需要去关注的事情。当我们去设计数据库表结构，对操作数据库时（尤其是查表时的SQL语句），我们都需要注意数据操作的性能。这里，我们不会讲过多的SQL语句的优化，而只是针对MySQL这一Web应用最多的数据库。希望下面的这些优化技巧对你有用。</span>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">1. 为查询缓存优化你的查询</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">大多数的MySQL服务器都开启了查询缓存。这是提高性最有效的方法之一，而且这是被MySQL的数据库引擎处理的。当有很多相同的查询被执行了多次的时候，这些查询结果会被放到一个缓存中，这样，后续的相同的查询就不用操作表而直接访问缓存结果了。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">这里最主要的问题是，对于程序员来说，这个事情是很容易被忽略的。因为，我们某些查询语句会让MySQL不使用缓存。请看下面的示例：</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141543225.jpg" alt="实例" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">上面两条SQL语句的差别就是 CURDATE() ，MySQL的查询缓存对这个函数不起作用。所以，像 NOW() 和 RAND() 或是其它的诸如此类的SQL函数都不会开启查询缓存，因为这些函数的返回是会不定的易变的。所以，你所需要的就是用一个变量来代替MySQL的函数，从而开启缓存。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">2. EXPLAIN 你的 SELECT 查询</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">使用 EXPLAIN 关键字可以让你知道MySQL是如何处理你的SQL语句的。这可以帮你分析你的查询语句或是表结构的性能瓶颈。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">EXPLAIN 的查询结果还会告诉你你的索引主键被如何利用的，你的数据表是如何被搜索和排序的……等等，等等。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">挑一个你的SELECT语句（推荐挑选那个最复杂的，有多表联接的），把关键字EXPLAIN加到前面。你可以使用phpmyadmin来做这个事。然后，你会看到一张表格。下面的这个示例中，我们忘记加上了group_id索引，并且有表联接：</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141543644.jpg" alt="表连接" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">我们可以看到，前一个结果显示搜索了 7883 行，而后一个只是搜索了两个表的 9 和 16 行。查看rows列可以让我们找到潜在的性能问题。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">3. 当只要一行数据时使用 LIMIT 1</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">当你查询表的有些时候，你已经知道结果只会有一条结果，但因为你可能需要去fetch游标，或是你也许会去检查返回的记录数。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">在这种情况下，加上 LIMIT 1 可以增加性能。这样一样，MySQL数据库引擎会在找到一条数据后停止搜索，而不是继续往后查少下一条符合记录的数据。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">下面的示例，只是为了找一下是否有“中国”的用户，很明显，后面的会比前面的更有效率。（请注意，第一条中是Select *，第二条是Select 1）</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141543897.jpg" alt="" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">4. 为搜索字段建索引</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">索引并不一定就是给主键或是唯一的字段。如果在你的表中，有某个字段你总要会经常用来做搜索，那么，请为其建立索引吧。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141544372.jpg" alt="为搜索字段建索引&#34;&#34;" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">从上图你可以看到那个搜索字串 “last_name LIKE ‘a%’”，一个是建了索引，一个是没有索引，性能差了4倍左右。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">另外，你应该也需要知道什么样的搜索是不能使用正常的索引的。例如，当你需要在一篇大的文章中搜索一个词时，如： “WHERE post_content LIKE ‘%apple%’”，索引可能是没有意义的。你可能需要使用MySQL全文索引 或是自己做一个索引（比如说：搜索关键词或是Tag什么的）</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">5. 在Join表的时候使用相当类型的例，并将其索引</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">如果你的应用程序有很多 JOIN 查询，你应该确认两个表中Join的字段是被建过索引的。这样，MySQL内部会启动为你优化Join的SQL语句的机制。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">而且，这些被用来Join的字段，应该是相同的类型的。例如：如果你要把 DECIMAL 字段和一个 INT 字段Join在一起，MySQL就无法使用它们的索引。对于那些STRING类型，还需要有相同的字符集才行。（两个表的字符集有可能不一样）</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141544676.jpg" alt="" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">6. 千万不要 ORDER BY RAND()</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">想打乱返回的数据行？随机挑一个数据？真不知道谁发明了这种用法，但很多新手很喜欢这样用。但你确不了解这样做有多么可怕的性能问题。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">如果你真的想把返回的数据行打乱了，你有N种方法可以达到这个目的。这样使用只让你的数据库的性能呈指数级的下降。这里的问题是：MySQL会不得不去执行RAND()函数（很耗CPU时间），而且这是为了每一行记录去记行，然后再对其排序。就算是你用了Limit 1也无济于事（因为要排序）</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">下面的示例是随机挑一条记录</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141545123.jpg" alt="随机挑一条记录" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">7. 避免 SELECT *</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">从数据库里读出越多的数据，那么查询就会变得越慢。并且，如果你的数据库服务器和WEB服务器是两\台\独立的服务器的话，这还会增加网络传输的负载。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">所以，你应该养成一个需要什么就取什么的好的习惯。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141545596.jpg" alt="" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">8. 永远为每张表设置一个ID</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">我们应该为数据库里的每张表都设置一个ID做为其主键，而且最好的是一个INT型的（推荐使用UNSIGNED），并设置上自动增加的AUTO_INCREMENT标志。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">就算是你 users 表有一个主键叫 “email”的字段，你也别让它成为主键。使用 VARCHAR 类型来当主键会使用得性能下降。另外，在你的程序中，你应该使用表的ID来构造你的数据结构。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">而且，在MySQL数据引擎下，还有一些操作需要使用主键，在这些情况下，主键的性能和设置变得非常重要，比如，集群，分区……</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">在这里，只有一个情况是例外，那就是“关联表”的“外键”，也就是说，这个表的主键，通过若干个别的表的主键构成。我们把这个情况叫做“外键”。比如：有一个“学生表”有学生的ID，有一个“课程表”有课程ID，那么，“成绩表”就是“关联表”了，其关联了学生表和课程表，在成绩表中，学生ID和课程ID叫“外键”其共同组成主键。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">9. 使用 ENUM 而不是 VARCHAR</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">ENUM 类型是非常快和紧凑的。在实际上，其保存的是 TINYINT，但其外表上显示为字符串。这样一来，用这个字段来做一些选项列表变得相当的完美。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">如果你有一个字段，比如“性别”，“国家”，“民族”，“状态”或“部门”，你知道这些字段的取值是有限而且固定的，那么，你应该使用 ENUM 而不是 VARCHAR。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">MySQL也有一个“建议”（见第十条）告诉你怎么去重新组织你的表结构。当你有一个 VARCHAR 字段时，这个建议会告诉你把其改成 ENUM 类型。使用 PROCEDURE ANALYSE() 你可以得到相关的建议。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">10. 从 PROCEDURE ANALYSE() 取得建议</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">PROCEDURE ANALYSE() 会让 MySQL 帮你去分析你的字段和其实际的数据，并会给你一些有用的建议。只有表中有实际的数据，这些建议才会变得有用，因为要做一些大的决定是需要有数据作为基础的。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">例如，如果你创建了一个 INT 字段作为你的主键，然而并没有太多的数据，那么，PROCEDURE ANALYSE()会建议你把这个字段的类型改成 MEDIUMINT 。或是你使用了一个 VARCHAR 字段，因为数据不多，你可能会得到一个让你把它改成 ENUM 的建议。这些建议，都是可能因为数据不够多，所以决策做得就不够准。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">在phpmyadmin里，你可以在查看表时，点击 “Propose table structure” 来查看这些建议</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">一定要注意，这些只是建议，只有当你的表里的数据越来越多时，这些建议才会变得准确。一定要记住，你才是最终做决定的人。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">11. 尽可能的使用 NOT NULL</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">除非你有一个很特别的原因去使用 NULL 值，你应该总是让你的字段保持 NOT NULL。这看起来好像有点争议，请往下看。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">首先，问问你自己“Empty”和“NULL”有多大的区别（如果是INT，那就是0和NULL）？如果你觉得它们之间没有什么区别，那么你就不要使用NULL。（你知道吗？在 Oracle 里，NULL 和 Empty 的字符串是一样的！)</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">不要以为 NULL 不需要空间，其需要额外的空间，并且，在你进行比较的时候，你的程序会更复杂。 当然，这里并不是说你就不能使用NULL了，现实情况是很复杂的，依然会有些情况下，你需要使用NULL值。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">下面摘自MySQL自己的文档：</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/2714154619.jpg" alt="摘自MySQL自己的文档&#34;&#34;" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">12. Prepared Statements</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">Prepared Statements很像存储过程，是一种运行在后台的SQL语句集合，我们可以从使用 prepared statements 获得很多好处，无论是性能问题还是安全问题。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">Prepared Statements 可以检查一些你绑定好的变量，这样可以保护你的程序不会受到“SQL注入式”攻击。当然，你也可以手动地检查你的这些变量，然而，手动的检查容易出问题，而且很经常会被程序员忘了。当我们使用一些framework或是ORM的时候，这样的问题会好一些。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">在性能方面，当一个相同的查询被使用多次的时候，这会为你带来可观的性能优势。你可以给这些Prepared Statements定义一些参数，而MySQL只会解析一次。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">虽然最新版本的MySQL在传输Prepared Statements是使用二进制形势，所以这会使得网络传输非常有效率。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">当然，也有一些情况下，我们需要避免使用Prepared Statements，因为其不支持查询缓存。但据说版本5.1后支持了。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">在PHP中要使用prepared statements，你可以查看其使用手册：mysqli 扩展 或是使用数据库抽象层，如： PDO.</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141546370.jpg" alt="" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">13. 无缓冲的查询</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">正常的情况下，当你在当你在你的脚本中执行一个SQL语句的时候，你的程序会停在那里直到没这个SQL语句返回，然后你的程序再往下继续执行。你可以使用无缓冲查询来改变这个行为。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">关于这个事情，在PHP的文档中有一个非常不错的说明： mysql_unbuffered_query() 函数：</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141548251.jpg" alt="" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">上面那句话翻译过来是说，mysql_unbuffered_query() 发送一个SQL语句到MySQL而并不像mysql_query()一样去自动fethch和缓存结果。这会相当节约很多可观的内存，尤其是那些会产生大量结果的查询语句，并且，你不需要等到所有的结果都返回，只需要第一行数据返回的时候，你就可以开始马上开始工作于查询结果了。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">然而，这会有一些限制。因为你要么把所有行都读走，或是你要在进行下一次的查询前调用 mysql_free_result() 清除结果。而且， mysql_num_rows() 或 mysql_data_seek() 将无法使用。所以，是否使用无缓冲的查询你需要仔细考虑。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">14. 把IP地址存成 UNSIGNED INT</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">很多程序员都会创建一个 VARCHAR(15) 字段来存放字符串形式的IP而不是整形的IP。如果你用整形来存放，只需要4个字节，并且你可以有定长的字段。而且，这会为你带来查询上的优势，尤其是当你需要使用这样的WHERE条件：IP between ip1 and ip2。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">我们必需要使用UNSIGNED INT，因为 IP地址会使用整个32位的无符号整形。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">而你的查询，你可以使用 INET_ATON() 来把一个字符串IP转成一个整形，并使用 INET_NTOA() 把一个整形转成一个字符串IP。在PHP中，也有这样的函数 ip2long() 和 long2ip()。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141548788.jpg" alt="" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">15. 固定长度的表会更快</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">如果表中的所有字段都是“固定长度”的，整个表会被认为是 “static” 或 “fixed-length”。 例如，表中没有如下类型的字段： VARCHAR，TEXT，BLOB。只要你包括了其中一个这些字段，那么这个表就不是“固定长度静态表”了，这样，MySQL 引擎会用另一种方法来处理。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">固定长度的表会提高性能，因为MySQL搜寻得会更快一些，因为这些固定的长度是很容易计算下一个数据的偏移量的，所以读取的自然也会很快。而如果字段不是定长的，那么，每一次要找下一条的话，需要程序找到主键。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">并且，固定长度的表也更容易被缓存和重建。不过，唯一的副作用是，固定长度的字段会浪费一些空间，因为定长的字段无论你用不用，他都是要分配那么多的空间。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">使用“垂直分割”技术（见下一条），你可以分割你的表成为两个一个是定长的，一个则是不定长的。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">16. 垂直分割</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">“垂直分割”是一种把数据库中的表按列变成几张表的方法，这样可以降低表的复杂度和字段的数目，从而达到优化的目的。（以前，在银行做过项目，见过一张表有100多个字段，很恐怖）</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">示例一：在Users表中有一个字段是家庭地址，这个字段是可选字段，相比起，而且你在数据库操作的时候除了个人信息外，你并不需要经常读取或是改写这个字段。那么，为什么不把他放到另外一张表中呢？ 这样会让你的表有更好的性能，大家想想是不是，大量的时候，我对于用户表来说，只有用户ID，用户名，口令，用户角色等会被经常使用。小一点的表总是会有好的性能。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">示例二： 你有一个叫 “last_login” 的字段，它会在每次用户登录时被更新。但是，每次更新时会导致该表的查询缓存被清空。所以，你可以把这个字段放到另一个表中，这样就不会影响你对用户ID，用户名，用户角色的不停地读取了，因为查询缓存会帮你增加很多性能。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">另外，你需要注意的是，这些被分出去的字段所形成的表，你不会经常性地去Join他们，不然的话，这样的性能会比不分割时还要差，而且，会是极数级的下降。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">17. 拆分大的 DELETE 或 INSERT 语句</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">如果你需要在一个在线的网站上去执行一个大的 DELETE 或 INSERT 查询，你需要非常小心，要避免你的操作让你的整个网站停止相应。因为这两个操作是会锁表的，表一锁住了，别的操作都进不来了。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">Apache 会有很多的子进程或线程。所以，其工作起来相当有效率，而我们的服务器也不希望有太多的子进程，线程和数据库链接，这是极大的占服务器资源的事情，尤其是内存。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">如果你把你的表锁上一段时间，比如30秒钟，那么对于一个有很高访问量的站点来说，这30秒所积累的访问进程/线程，数据库链接，打开的文件数，可能不仅仅会让你泊WEB服务Crash，还可能会让你的整台服务器马上掛了。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">所以，如果你有一个大的处理，你定你一定把其拆分，使用 LIMIT 条件是一个好的方法。下面是一个示例：</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><img style="margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px;" src="http://www.oeedu.com/upload/2010/7/27141549854.jpg" alt="" /></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">18. 越小的列会越快</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">对于大多数的数据库引擎来说，硬盘操作可能是最重大的瓶颈。所以，把你的数据变得紧凑会对这种情况非常有帮助，因为这减少了对硬盘的访问。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">参看 MySQL 的文档 Storage Requirements 查看所有的数据类型。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">如果一个表只会有几列罢了（比如说字典表，配置表），那么，我们就没有理由使用 INT 来做主键，使用 MEDIUMINT, SMALLINT 或是更小的 TINYINT 会更经济一些。如果你不需要记录时间，使用 DATE 要比 DATETIME 好得多。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">当然，你也需要留够足够的扩展空间，不然，你日后来干这个事，你会死的很难看，参看Slashdot的例子（2009年11月06日），一个简单的ALTER TABLE语句花了3个多小时，因为里面有一千六百万条数据。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">19. 选择正确的存储引擎</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">在 MySQL 中有两个存储引擎 MyISAM 和 InnoDB，每个引擎都有利有弊。酷壳以前文章《MySQL: InnoDB 还是 MyISAM?》讨论和这个事情。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">MyISAM 适合于一些需要大量查询的应用，但其对于有大量写操作并不是很好。甚至你只是需要update一个字段，整个表都会被锁起来，而别的进程，就算是读进程都无法操作直到读操作完成。另外，MyISAM 对于 SELECT COUNT(*) 这类的计算是超快无比的。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">InnoDB 的趋势会是一个非常复杂的存储引擎，对于一些小的应用，它会比 MyISAM 还慢。他是它支持“行锁” ，于是在写操作比较多的时候，会更优秀。并且，他还支持更多的高级应用，比如：事务。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">下面是MySQL的手册</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">target=”_blank”MyISAM Storage Engine</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">InnoDB Storage Engine</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">20. 使用一个对象关系映射器（Object Relational Mapper）</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">使用 ORM (Object Relational Mapper)，你能够获得可靠的性能增涨。一个ORM可以做的所有事情，也能被手动的编写出来。但是，这需要一个高级专家。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">ORM 的最重要的是“Lazy Loading”，也就是说，只有在需要的去取值的时候才会去真正的去做。但你也需要小心这种机制的副作用，因为这很有可能会因为要去创建很多很多小的查询反而会降低性能。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">ORM 还可以把你的SQL语句打包成一个事务，这会比单独执行他们快得多得多。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">目前，个人最喜欢的PHP的ORM是：Doctrine。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"><strong style="list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; margin: 0px;">21. 小心“永久链接”</strong></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">“永久链接”的目的是用来减少重新创建MySQL链接的次数。当一个链接被创建了，它会永远处在连接的状态，就算是数据库操作已经结束了。而且，自从我们的Apache开始重用它的子进程后——也就是说，下一次的HTTP请求会重用Apache的子进程，并重用相同的 MySQL 链接。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">PHP手册：mysql_pconnect()</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">在理论上来说，这听起来非常的不错。但是从个人经验（也是大多数人的）上来说，这个功能制造出来的麻烦事更多。因为，你只有有限的链接数，内存问题，文件句柄数，等等。</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;"></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #4d4b4c; font-family: Arial; line-height: 18px; background-color: #ffffff; margin: 0px;">而且，Apache 运行在极端并行的环境中，会创建很多很多的了进程。这就是为什么这种“永久链接”的机制工作地不好的原因。在你决定要使用“永久链接”之前，你需要好好地考虑一下你的整个系统的架构。</p>
&#160;

&#160;

&#160;

&#160;

<a href="http://ourmysql.com/archives/980">二十种实战调优MySQL性能优化的经验 &#124; OurMySQL &#124; 我们致力于一个MySQL知识的分享网站</a>.]]></description>
		<wfw:commentRss>http://www.huoyue.org/mysql-optimization/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>php自动销毁删除session</title>
		<link>http://www.huoyue.org/php-auto-delete-session</link>
		<comments>http://www.huoyue.org/php-auto-delete-session#comments</comments>
		<pubDate>Sun, 05 Feb 2012 16:53:35 +0000</pubDate>
		<dc:creator>火跃</dc:creator>
				<category><![CDATA[PHP+mysql]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://www.huoyue.org/?p=403</guid>
		<description><![CDATA[<p style="font-family: 'Courier New'; font-size: 12px; line-height: 20px; background-color: #ffffff;">先说说现象：今天登录<a style="color: #333333; text-decoration: none;" href="http://www.9streets.cn/">9街</a>后台的时候，很奇怪一登录就退出，后台代码一直没有改动过，查了一下原因，找到了根本原因，后面会贴上找到的相关文档。解决办法就是在产生的session的页面session_star();加上以下三句代码：</p>

<blockquote>
<ol>
	<li>ini_set("session.gc_divisor", 1);  </li>
	<li>ini_set("session.gc_maxlifetime", 5);  </li>
	<li>ini_set("session.cookie_lifetime", 10);  </li>
</ol>
</blockquote>
<p style="font-family: 'Courier New'; font-size: 12px; line-height: 20px; background-color: #ffffff;">以下是转摘网上文档</p>
<p style="font-family: 'Courier New'; font-size: 12px; line-height: 20px; background-color: #ffffff;"><span style="font-family: helvetica, arial, sans-serif; font-size: x-small;">首先 gc是什么?</span></p>
gc, 是garbage collection 的简称.这个进程一般都跟着每起一个SESSION而开始运行的.gc目的是为了在session文件过期以后自动销毁删除这些文件.

1、session_gc_probaility
PHP默认不是每个SESSION启动都会启动一个GC来跟踪。这个参数是控制gc跟session启动概率。默认 1。值越大，概率越大。

2、session.gc_divisor
功能同上。 默认100。值越小，概率越大。

3、session.gc_maxlifetime
超过设定时间，gc就认为是垃圾文件。

总结
session_gc_probaility和session.gc_divisor是一对控制gc启动的概率的两个参数。前者是分子，后者是分母。默认是1/100。 1%的几率。 也就是说100个请求中只有一个gc会伴随100个中的某个请求而启动。
session处理是所有的Web应用都必须面对的问题。PHP中对session有效期的处理，和其他的解决方案有着很大的不同，这是和PHP的工作机制相关的。
<div id="sina_keyword_ad_area2" class="articalContent  " style="font-family: 'Courier New'; font-size: 12px; line-height: 20px; background-color: #ffffff;"><wbr> <wbr> <wbr> 在传统的client/server应用中，对于session失效的情况，可以交给网络协议自己来处理。无论是client端主动关闭连接，还是因为网络异常而导致的连接中断，server端都能够得到通知，触发连接中断的事件。只要编程响应这一事件，执行指定的操作即可。
<wbr> <wbr> <wbr> 但对于web应用来说，情况却完全不一样。HTTP协议本身是无状态的，也就是说，每当client/server完成一次请求/响应的过程后，连接就会被断开。在断开连接以后，server并不知道client是否继续“在线”，还会继续发送下一次请求。
<wbr> <wbr> <wbr> 换句话说，无论client端的用户已经关闭了浏览器窗口，还是用户仅仅在阅读当前网页并准备在下一秒钟继续浏览，或者用户因为Windows崩溃/停电/硬盘坏掉/网线被拔/地球爆炸而彻底无法再发送下一个请求，server都一无所知。（在HTTP 1.1中，浏览器可以通过keep-alive参数，来通知server不要在响应请求后主动断开连接，从而实现物理上的长连接。但是，这只是为了提高网络传输的性能而采取的措施，HTTP 在逻辑上仍然是无状态的。）因此，只能通过某种模拟的方式来判断当前session是否有效。如果某个session在超过一段时间后没有对server 端发出请求，server都会判断用户已经“离线”，当前session失效，并触发连接中断的事件。要做到这一点，server需要运行一个后台线程，定时扫描所有的session信息，判断session是否已经超时。
<wbr> <wbr> <wbr> PHP处理session的原理也不例外，但是在具体的实现方式上，却与众不同。这是因为，由于PHP的工作机制，它并没有一个后台线程，来定时地扫描session信息并判断其是否失效。它的解决之道是，当一个有效请求发生时，PHP会根据某个概率，来决定是否调用一个GC（Garbage Collector）。
<wbr> <wbr> <wbr> GC的工作，就是扫描所有的session信息，用当前时间减去session的最后修改时间（modified date），同配置参数（configuration option）session.gc_maxlifetime的值进行比较，如果生存时间已经超过gc_maxlifetime，就把该session删除。
<wbr> <wbr> <wbr> 这是很容易理解的，因为如果每次请求都要调用GC代码，那么PHP的效率就会低得令人吃不消了。这个概率取决于配置参数 session.gc_probability/session.gc_divisor的值（可以通过php.ini或者ini_set()函数来修改）。
<wbr> <wbr> <wbr> 默认情况下，session.gc_probability = 1，session.gc_divisor=100，也就是说有1%的可能性会启动GC。这三个参 数，session.gc_maxlifetime/session.gc_probability/session.gc_divisor都可以通过 php.ini或者ini_set()函数来修改。但要记得，如果使用ini_set()函数的话，必须在每一个页面的开始处都调用 ini_set()。
这又导致了另外一个问题，gc_maxlifetime只能保证session生存的最短时间，并不能够保存在超过这一时间之后session信息立即会得到删除。因为GC是按概率启动的，可能在某一个长时间内都没有被启动，那么大量的session在超过 gc_maxlifetime以后仍然会有效。当然，发生这种情况的概率很小，但是如果你的应用对 session的失效期要求很精确的话，这会导致很严重的问题。解决这个问题的一个方法是，把 session.gc_probability/session.gc_divisor的机率提高，如果提到100%，就会彻底解决这个问题，但显然会对性能造成严重的影响。另一个方法是放弃PHP的GC，自己在代码中判断当前session的生存时间，如果超出了 gc_maxlifetime，就清空当前session。
<wbr> <wbr> <wbr> PHP中的session有效期默认是1440秒（24分钟），也就是说，客户端超过24分钟没有刷新，当前session就会失效。要修改这个默认值，正确的解决办法是修改配置参数session.gc_maxlifetime。
我曾经在网上搜索过这个问题的解决方式，找到的结果千奇百怪。
<wbr> <wbr> <wbr> 有的说要设置“session_life_time”，据我知所，PHP中没有这个参数。有的说要调用session_set_cookie_params，或者设置 session.cookie_lifetime，这仅仅用于设置client端cookie的生存时间，换言之，只当client端cookie的生存时间小于server端的session生存期时，修改这个值才有效，并且最长不能超过server端的session生存期，原因很简单，当 server端的session已经失效时，client端cookie的生存时间再长也是没有意义的。还有的说要调用 session_cache_expire，这个参数用于通知浏览器和proxy，当前页面的内容应该被缓存多长时间，和session的生存期并没有直接关系。
<wbr> <wbr> <wbr> 听起来，这种解决方案很完美。但是，当你在实际中尝试修改session.gc_maxlifetime的值的时候，你很可能会发现，这个参数基本不起作用，session有效期仍然保持24分钟的默认值。甚至可能出现，在开发环境下工作正常，在服务器上却无效！
为了彻底解决这个问题，需要对PHP的工作细节进行进一步的分析。
在默认情况下，PHP 中的session信息会以文本文件的形式，被保存在系统的临时文件目录中。这个路径由配置参数session.save_path指定。在Linux下，这一路径通常为\tmp，在 Windows下通常为C:\Windows\Temp。当服务器上有多个PHP应用时，它们会把自己的session文件都保存在同一个目录中（因为它们使用同一个session.save_path参数）。同样地，这些PHP应用也会按一定机率启动GC，扫描所有的session文件。
问题在于，GC在工作时，并不会区分不同站点的session。举例言之，站点A的gc_maxlifetime设置为2小时，站点B的 gc_maxlifetime设置为默认的24分钟。当站点B的GC启动时，它会扫描公用的临时文件目录，把所有超过24分钟的session文件全部删除掉，而不管它们来自于站点A或B。这样，站点A的gc_maxlifetime设置就形同虚设了。
<wbr> <wbr> <wbr> 找到问题所在，解决起来就很简单了。在页面的开始处调用session_save_path()函数，它能够修改session.save_path参 数，把保存session的目录指向一个专用的目录，例如\tmp\myapp\。这样，gc_maxlifetime参数就工作正常了。
<wbr> <wbr> <wbr> 使用公用的session.save_path还会导致安全性问题，因为这意味着，同一台服务器上的其它PHP程序也可以读取你的站点的session文 件，这可能被用于黑客攻击。另一个问题是效率：在一个繁忙的站点中，可能存在成千上万个session文件，而把许多不同网站的session文件都放在 同一个目录下，无论是对单个文件的读写，还是遍历所有文件进行GC，都无疑会导致性能的降低。因此，如果你的PHP应用和别的PHP应用运行在同一台服务 器上的话，强烈建议你使用自己的 session.save_path。
<wbr> <wbr> <wbr> 严格地来说，这算是PHP的一个bug。当PHP在进行GC时，它应该区别来自不同站点的session文件，并应用不同的gc_maxlifetime值。目前，最新的PHP 5.2.X仍然存在这个问题。
<wbr> <wbr> <wbr> 上文说到，在一个繁忙的站点中，可能存在成千上万个session文件，即使区分了不同站点的session.save_path目录，单个站点的session文件数目仍然可能导致效率问题。</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></div>
<div class="articalContent  " style="font-family: 'Courier New'; font-size: 12px; line-height: 20px; background-color: #ffffff;">转自<a href="http://www.9streets.cn/art-php-498.html">http://www.9streets.cn/art-php-498.html</a></div>]]></description>
		<wfw:commentRss>http://www.huoyue.org/php-auto-delete-session/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>有关SQL模糊查询</title>
		<link>http://www.huoyue.org/sql-like</link>
		<comments>http://www.huoyue.org/sql-like#comments</comments>
		<pubDate>Sun, 05 Feb 2012 16:46:51 +0000</pubDate>
		<dc:creator>火跃</dc:creator>
				<category><![CDATA[PHP+mysql]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[模糊查询]]></category>

		<guid isPermaLink="false">http://www.huoyue.org/?p=401</guid>
		<description><![CDATA[执行数据库查询时，有完整查询和模糊查询之分。

一般模糊语句如下：

SELECT 字段 FROM 表 WHERE 某字段 Like 条件

其中关于条件，SQL提供了四种匹配模式：

1，%：表示任意个或多个字符。可匹配任意类型和长度的字符，有些情况下若是中文，请使用两个百分号(%%)表示。

比如 SELECT * FROM [user] WHERE u_name LIKE '%三%'

将会把u_name为“张三”，“张猫三”、“三脚猫”，“唐三藏”等等有“三”的记录全找出来。

另外，如果需要找出u_name中既有“三”又有“猫”的记录，请使用and条件

SELECT * FROM [user] WHERE u_name LIKE '%三%' AND u_name LIKE '%猫%'

若使用 SELECT * FROM [user] WHERE u_name LIKE '%三%猫%'

虽然能搜索出“三脚猫”，但不能搜索出符合条件的“张猫三”。

2，_： 表示任意单个字符。匹配单个任意字符，它常用来限制表达式的字符长度语句：

比如 SELECT * FROM [user] WHERE u_name LIKE '_三_'

只找出“唐三藏”这样u_name为三个字且中间一个字是“三”的;

再比如 SELECT * FROM [user] WHERE u_name LIKE '三__';

只找出“三脚猫”这样name为三个字且第一个字是“三”的;

3，[ ]：表示括号内所列字符中的一个(类似正则表达式)。指定一个字符、字符串或范围，要求所匹配对象为它们中的任一个。

比如 SELECT * FROM [user] WHERE u_name LIKE '[张李王]三'

将找出“张三”、“李三”、“王三”(而不是“张李王三”);

如 [ ] 内有一系列字符(01234、abcde之类的)则可略写为“0-4”、“a-e”

SELECT * FROM [user] WHERE u_name LIKE '老[1-9]'

将找出“老1”、“老2”、……、“老9”;

4，[^ ] ：表示不在括号所列之内的单个字符。其取值和 [] 相同，但它要求所匹配对象为指定字符以外的任一个字符。

比如 SELECT * FROM [user] WHERE u_name LIKE '[^张李王]三'

将找出不姓“张”、“李”、“王”的“赵三”、“孙三”等;

SELECT * FROM [user] WHERE u_name LIKE '老[^1-4]';

将排除“老1”到“老4”，寻找“老5”、“老6”、……

5，查询内容包含通配符时

由于通配符的缘故，导致我们查询特殊字符“%”、“_”、“[”的语句无法正常实现，而把特殊字符用“[ ]”括起便可正常查询。据此我们写出以下函数：

function sqlencode(str)

str=replace(str,"';","';';")

str=replace(str,"[","[[]") ';此句一定要在最先

str=replace(str,"_","[_]")

str=replace(str,"%","[%]")

sqlencode=str

end function

通过<a href="http://www.php100.com/html/webkaifa/database/SQLserver/2012/0201/9753.html">有关SQL模糊查询</a>.]]></description>
		<wfw:commentRss>http://www.huoyue.org/sql-like/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE 关于X-UA-Compatible</title>
		<link>http://www.huoyue.org/x-ua-compatible</link>
		<comments>http://www.huoyue.org/x-ua-compatible#comments</comments>
		<pubDate>Fri, 03 Feb 2012 03:13:25 +0000</pubDate>
		<dc:creator>火跃</dc:creator>
				<category><![CDATA[CSS+DIV]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[X-UA-Compatible]]></category>

		<guid isPermaLink="false">http://www.huoyue.org/?p=399</guid>
		<description><![CDATA[关于X-UA-Compatible

目前绝大多数网站都用

&#60;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" &#62;

来作为IE8的兼容方法，虽然微软将IE向标准迈进了一大步，而事实上IE8还存在一系列渲染的奇怪现象是不争的事实。

谁让IE6那么多呢，或许2014年以后我们可以有更多的时间去关心IE8，而不是IE6或者IE7。

在X-UA-Compatible中可用的方法有：

&#60;meta http-equiv="X-UA-Compatible" content="IE=5" &#62;

&#60;meta http-equiv="X-UA-Compatible" content="IE=7" &#62;

&#60;meta http-equiv="X-UA-Compatible" content="IE=8" &#62;

&#60;meta http-equiv="X-UA-Compatible" content="IE=edge" &#62;

其中最后一行是永远以最新的IE版本模式来显示网页的。

另外加上

&#60;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" &#62;

&#60;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" &#62;

而使用，Emulate模式后则更重视&#60;!DOCTYPE&#62;所以目前来说还是以

&#60;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" &#62;

为首选。微软自己创下的罪孽让他自己去扫吧。]]></description>
		<wfw:commentRss>http://www.huoyue.org/x-ua-compatible/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

