我的代码:
public function select($tbl,$info,$cond = null) {
if (!is_array($info)) {
return false;
}
$query = "SELECT `" . implode("`,`", $info) . "` FROM " . $this->escapeString($tbl) . (is_null($cond) ? "" : " WHERE " . $this->generateConditions($cond));
$query = $this->escapeString($query);
if ($prep = mysqli_prepare($this->connection,$query)) {
$types = "";
if (!is_null($cond)) {
$types = $this->generateTypes($cond,$types);
}
$params = array();
array_push($params, $prep);
array_push($params, $types);
if (!is_null($cond)) {
foreach ($cond as $key => $value) {
array_push($params, $value);
}
}
if (call_user_func_array("mysqli_stmt_bind_param", $this->refValues($params))) {
mysqli_stmt_execute($prep);
$results = array();
$results[] = $prep;
$row = new stdClass();
foreach ($info as $key => $value) {
$results[] = &$row->$value;
}
if (call_user_func_array("mysqli_stmt_bind_result", $results)) {
$resultArray = array();
while (mysqli_stmt_fetch($prep)) {
error_log("[PROJECT] ROW: " . print_r($row,true));
array_push($resultArray, $row);
}
error_log("[PROJECT] TEST: " . print_r($resultArray,true));
mysqli_stmt_close($prep);
unset($prep);
return (count($resultArray) == 1) ? $resultArray[0] : (array)$resultArray;
}
mysqli_stmt_close($prep);
unset($prep);
return false;
}
}
return false;
}
这是我从数据库中选择内容的php方法。但是似乎有一个错误:
$resultArray = array();
while (mysqli_stmt_fetch($prep)) {
error_log("[PROJECT] ROW: " . print_r($row,true));
array_push($resultArray, $row);
}
error_log("[PROJECT] Array: " . print_r($resultArray,true));
您认为无论这些$row
是什么,都可以在阵列中找到吗?
那么这里是输出(因为日志太长,我做了一个概念):
ROW: stdClass Object\n(\n [token] => RUMtN0tWNDU3MDY3QjE0NDM4M1M=\n...
ROW: stdClass Object\n(\n [token] => RUMtNU1DNjcwNjYxNTQyNjIxNTc=\n...
Array: stdClass Object\n(\n [token] => RUMtN0tWNDU3MDY3QjE0NDM4M1M=\n,
stdClass Object\n(\n [token] => RUMtN0tWNDU3MDY3QjE0NDM4M1M=\n
因此,虽然行不同,但只有一行出现在数组中且重复。有人对此有解释吗?