我正在尝试使用 PDO 连接在我的 SQL 记录中查找最小值。记录是 varchar,因此必须将其转换为 int 才能找到最小的。我被困在这个问题上:
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));
?>