mysql php:如何正确保存查询结果[关闭]

my code:

$db = new PDO('mysql:host='.DBx.';dbname='.DBx.';charset=utf8', DBx, DBx);
$sql = "SELECT  max(date_insert) FROM OrderAUS LIMIT 1" ;
$val = $db->query($sql);

the result of the query should be one date, i need to put it in a $variable (just the date, not an array of results). Can you please show me the correct way to do it?

You need to tell MYSQL like this

$db = new PDO('mysql:host='.DBx.';dbname='.DBx.';charset=utf8', DBx, DBx);
$sql = "SELECT  max(date_insert) as date FROM OrderAUS LIMIT 1" ;
$var = $db->query($sql);
$result = $var->fetchColumn();
print_r($result);