【发布时间】:2014-12-10 19:16:36
【问题描述】:
您好,我正在尝试查看 Selected 查询的内容...但是出现错误:
mysqli_num_rows() 期望参数 1 为 mysqli_result ...
$stmt= $this->conn->prepare("SELECT * FROM table") or die(mysql_error());
$result = $stmt->execute();
// check for empty result
if (mysqli_num_rows($result) > 0) {
..
}
编辑 新错误 mysqli_fetch_array() 期望参数 1 为 mysqli_result,对象在...中给出...
$stmt= $this->conn->prepare("SELECT * FROM table") or die(mysqli_error());
$stmt->execute();
$stmt->store_result();
// check for empty result
if ($stmt->num_rows > 0) {
// looping through all results
$response["array"] = array();
while ($row = mysqli_fetch_array($stmt)) {
... }
我想我明白了:
while ($row = $stmt->fetchAll()) {
// temp user array
$array= array();
$array["bla"] = $row["bla"];
... }
但我只得到“null”作为值...?
编辑
现在我明白了:
$stmt->bind_result($column1, $column2...)
然后
$array["bla"] = $column1; $array["bla2"] = $column2;
但是是否可以绑定所有列而不将每个列放入变量中? 或者是不是可以使用这个:
$array["bla"] = $row["bla"];
所以它将“bla”列的行中的值放入$array[bla]?
因为我解决它的方式似乎很困难
【问题讨论】:
-
您将 OOP 与标准代码混合在一起。这是行不通的。解决这个问题,你应该很高兴
-
还将 MySQL API 与
mysql_error()混合使用