考虑这个名为' refresh'
的表格-------------------------------
| id | region | server | name |
-------------------------------
| 1 | US | Boron | aa |
| 2 | US | Argon | ab |
| 3 | US | Boron | ac |
| 4 | US | Argon | ad |
| | | | |
-------------------------------
我不明白为什么我一直收到错误... "在第12行&#34上的refreshNow.php中的非对象上调用成员函数fetch_array();
$conn = mysqli_connect("location", "username", "password", "database");
if (mysqli_connect_errno()) {
exit();
}
if($result = $conn->query("SELECT * FROM refresh")) {
while ($newArray = $result->fetch_array()) { <--- line 12
$id = $newArray['id'];
$region = $newArray['region'];
$server = $newArray['server'];
$name = $newArray['name'];
...
}
}
我必须遗漏一些东西,因为这很久以前是用mysql编写的,但现在当我们把它切换到mysqli时,它让我很头疼,我似乎无法弄明白。
编辑:
固定。哈哈哈..这是非常愚蠢的。我在循环中重新定义$result
,因此出错。疲倦时不要编码。
答案 0 :(得分:-1)
也许是一个愚蠢的问题,但你定义了$ result?或者fetch_array()是否接受任何参数?
答案 1 :(得分:-1)
这是因为查询失败。
查询后检查错误编号。
$conn = mysqli_connect("location", "username", "password", "database");
if (mysqli_connect_errno()) {
exit();
}
$result = $conn->query("SELECT * FROM refresh");
if ( $conn->errno > 0 )
{
print "An error occurred: " . $conn->error;
exit;
}
else {
while ($newArray = $result->fetch_array()) { <--- line 12
$id = $newArray['id'];
$region = $newArray['region'];
$server = $newArray['server'];
$name = $newArray['name'];
...
}
}