我要檢索表中的所有數據,所以我用這個代碼PHP警告預計參數1是資源,對象給出
<?php
include("config.php");
$sql = "SELECT * FROM ".$USERS;
$sql_result = mysqli_query($connection, $sql);
if ($sql_result) {
while ($result = mysql_fetch_assoc($sql_result)) {
echo $result;
}
}
else {
die ('Could not execute SQL query '.$sql);
}
?>
卻得到了這樣的警告:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource,
object given in C:\xampp\htdocs\newSDP\phpscript\users.php on line 6
哪有我修復它?
不能混搭mysql_ *和* mysqli_功能。 –
使用mysqli_fetch_assoc()函數代替mysql_fetch_assoc – Bhaskar
[mysqli \ _fetch \ _array()/ mysqli \ _fetch \ _assoc()/ mysqli \ _fetch \ _row()的可能重複需要參數1爲資源或mysqli \ _result,布爾給定](http://stackoverflow.com/questions/2973202/mysqli-fetch-array-mysqli-fetch-assoc-mysqli-fetch-row-expects-parameter-1) – Jens