时间:2021-07-01 10:21:17 帮助过:2人阅读
/*
* $sql 要执行的sql语句
* $arg sql中要用到的参数(数组)
* $keyfield 返回数组中的键名(若有)
* $silent 已以哪种方式查询(默认是mysql_query,还有mysql_unbuffered_query)
*/
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)) {
//将查询的资源放到$data数组中,若$keyfield有值,则将$keyfield作为$data的key值
if ($keyfield && isset($row[$keyfield])) {
$data[$row[$keyfield]] = $row;
} else {
$data[] = $row;
}
}
self::$db->free_result($query);//释放资源
return $data;//二维数组
}
//查询uid为1的用户的所有信息
$res=DB::fetch_all("SELECT * FROM %t WHERE uid=%d",array('common_member',1));