我的SQL查詢計算滿足條件的行數。有時這個值是0或1.這會產生一個關於返回布爾值的錯誤。Mysql_fetch_array顯示值爲0或1的警告
這怎麼可以避免?我不應該使用mysql_fetch_array
?
// Query the db to count the # of comments.
$price_change_dbo =
mysql_query("
SELECT COUNT(1) AS comment_count
FROM comments
WHERE user_id = '{$user_id}';"
);
// Use the result.
$price_change_row = mysql_fetch_array($price_change_dbo);
這裏是警告:
Warning: mysql_fetch_array() expects parameter 1 to be resource,
boolean given in /Applications/MAMP/... on line 1.
根本不應該使用任何'mysql_'函數。看看'PDO'。 – clentfort
@clentfort爲什麼不'mysqli_'? – Kermit
你的查詢是錯誤的.... –