尝试在MAX()
中选择PHP MySQL
,但未显示任何结果,也未显示错误(错误显示在
error_reporting(E_ALL);
ini_set('display_errors', 1);
)。
我尝试过:
$user_home = new USER();
$select_max = $user_home->runQuery("SELECT MAX(Gems) AS highest FROM users");
$get_max = $select_max->fetch(PDO::FETCH_ASSOC);
$highest = $get_max['highest'];
echo $highest;
课程文件:
public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}
public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}
答案 0 :(得分:2)
您不执行查询,只是准备它并获取数据...
$select_max = $user_home->runQuery("SELECT MAX(Gems) AS highest FROM users");
$select_max->execute();
$get_max = $select_max->fetch(PDO::FETCH_ASSOC);
$highest = $get_max['highest'];
echo $highest;