discuz x2.5中 fetch_all函数求解释,该怎么处理

WBOY
Release: 2016-06-13 12:10:11
Original
1654 people have browsed it

discuz x2.5中 fetch_all函数求解释
public static function fetch_all($sql, $arg = array(), $keyfield = '', $silent=false) {

$data = array();
$query = self::query($sql, $arg, $silent, false);
while ($row = self::$db->fetch_array($query)) {
if ($keyfield && isset($row[$keyfield])) {
$data[$row[$keyfield]] = $row;
} else {
$data[] = $row;
}
}
self::$db->free_result($query);
return $data;
}

请大侠解释下这个函数,最好每句代码与函数参数代表的意思都解释下。谢谢啊!
------解决思路----------------------

<br />/*<br />*	$sql		要执行的sql语句<br />*	$arg		sql中要用到的参数(数组)<br />*	$keyfield	返回数组中的键名(若有)<br />*	$silent		已以哪种方式查询(默认是mysql_query,还有mysql_unbuffered_query)<br />*/<br />public static function fetch_all($sql, $arg = array(), $keyfield = '', $silent=false) {<br />	<br />	$data = array();<br />	$query = self::query($sql, $arg, $silent, false);//执行查询<br />	while ($row = self::$db->fetch_array($query)) {<br />		//将查询的资源放到$data数组中,若$keyfield有值,则将$keyfield作为$data的key值<br />		if ($keyfield && isset($row[$keyfield])) {<br />			$data[$row[$keyfield]] = $row;<br />		} else {<br />			$data[] = $row;<br />		}<br />	}<br />	self::$db->free_result($query);//释放资源<br />	return $data;//二维数组<br />}<br />
Copy after login

一个例子
<br />//查询uid为1的用户的所有信息<br />$res=DB::fetch_all("SELECT * FROM %t WHERE uid=%d",array('common_member',1));<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!