我错过了一些明显的东西.这是一个简单的
PHP,散落着调试回声:
function echo_rows(&$res) {
$rows= array();
while ($row= $res->fetch()) {
echo $row['ccorID'] . "\r\n";
$rows[]= $row;
echo $rows[0]['ccorID'] . "\r\n";
}
echo "---.---\r\n";
echo count($rows) . "\r\n";
foreach($rows as $row) {
echo $row['ccorID'] . "\r\n";
}
echo json_encode($rows);
}
这是我在回复中看到的内容:
0
0
3
3
13
13
182
182
---.---
4
182
182
182
182
我觉得很清楚: –
任何人都知道我需要做什么来获得$row的副本(这是一个关联数组)?
谢谢.
编辑:因为很多人都坚持要知道$res是什么,所以这是课程.我真的相信这更容易混淆而不是启发(因此我的OP遗漏).
class mysqlie_results {
private $stmt;
private $paramArray= array();
private $assocArray= array();
public function __construct(&$stmt) {
$this->stmt= $stmt;
$meta= $stmt->result_metadata();
while ($colData= $meta->fetch_field()) {
$this->paramArray[]= &$this->assocArray[$colData->name];
}
call_user_func_array(array($stmt,'bind_result'),$this->paramArray);
$meta->close();
}
public function __destruct() {
$this->stmt->free_result();
}
public function fetch() {
return $this->stmt->fetch()? $this->assocArray : false;
}
}