我正在尝试使用PDO连接在我的SQL记录中查找最小值。记录是varchar,所以必须将其转换为int才能找到最小值。我被困在这个问题上:PHP SQL:使用PDO查找最小值
mysql_fetch_assoc() expects parameter 1 to be resource, array given
问题是我不知道如何从PDO连接获取资源。该查询是有效的。
<?php
//load and connect
require("config.inc.php");
//change varcar to ints and put into array
$query = "SELECT score FROM easy";
$stmt = $db->prepare($query);
$result = $stmt->execute();
$rows = $stmt->fetchAll();
$scoreArray = array();
$index = 0;
while($row = mysql_fetch_assoc($rows)){
$scoreArray[$index] = intval($row);
$index++;
}
$smallest = min($scoreArray);
$response["success"] = 0;
$response["message"] = "The min is: ".$smallest;
echo(json_encode($response));
?>
您需要使用不PDO但** ** SQL。因为它正是SQL正好为 –
** mysql_fetch_assoc **与旧的折旧** mysql **函数有关。它与** PDO **无关。 – Subin