最近我偶然发现了一个以前可以正常工作的库中的错误,如果我能弄清楚它在哪里,我会被诅咒的。
代码示例如下,对于其中的调试内容,我深表歉意,但我正在努力让它工作。
问题是 $temp 是一个具有正确键(列名)的数组,但所有值都是 NULL。
我认为问题出在
call_user_func_array(array($query, 'bind_result'), $params);
有点,但我无法真正理解它。
public function fetchRows(){
error_reporting(E_ALL+E_NOTICE);
$args = func_get_args();
$sql = array_shift($args);
traceVar($sql, "Query");
$colTypes = array_shift($args);
if (!$query = $this->prepare($sql, $colTypes)) {
die('Please check your sql statement : unable to prepare');
}
if (count($args)){
traceVar($args,'Binding params with');
call_user_func_array(array($query,'bindParam'), $args);
}
$query->execute();
$meta = $query->result_metadata();
while ($field = $meta->fetch_field()) {
$params[] = &$row[$field->name];
}
traceVar($params,'Binding results with');
call_user_func_array(array($query, 'bind_result'), $params);
while ($query->fetch()) {
traceVar($row,'After fetch');
$temp = array();
foreach($row as $key => $val) {
$temp[$key] = $val;
}
$result[] = $temp;
}
$meta->free();
$query->close();
//self::close_db_conn();
return $result;
}