老是喜欢用select *,后来自己觉着不行,会影响速度,今天俺 做一个测试看看倒底有多大影响? 数据表结构: CREATE TABLE `xoops__art_text` ( `text_id` int(11) NOT NULL auto_increment, `art_id` int(11) NOT NULL default ‘0’, `text_title` varchar(255) NOT NULL default ‘’, `text_body` longblob, PRIMARY KEY (`text_id`), KEY `art_id` (`art_id`) ) 测试文件代码: div{ border:1px solid black; background-color:#888; height:20px; margin-left:30px; display:inline; align:left; text-align:right; } reset(); for($j=0;$j<$max;$j++) $rs=mysql_query($sql); $times[$i]=$time1->tick(); if($times[$i]>$max) $max=$times[$i]; $i++; } print_r($times); $texts=array(); $texts[]=”method a:”; $texts[]=”method b:”; $texts[]=”method c:”; echo “
“; echo “max:$max;”; echo “
“; $i=0; foreach($times as $time) { echo $texts[$i++]; echo “

 “; echo $time.”ms “; echo “

“; } } test(); test(); test(); test(); test(); test(); test(); test(); class timer { var $_start; var $_current; function timer() { /** 这是记录下开始操作时的时间。 */ $this->_start = array_sum(explode(‘ ‘, microtime())); } function tick() { $this->_current = round((array_sum(explode(‘ ‘, microtime()))-$this->_start)*1000, 0); return $this->_current; } function reset() { $this->timer(); } } ?> 测出来的一组结果: method a: 79ms method b: 79ms method c: 1010ms 相比之下,当用了select * 之后,只多取了一个text/longblob类型的字段,整个时间相差了十几倍! 所以,以后写代码,俺 还是要勤快一点,用select id,name,title 而不能用select *.那样太浪费资源了.