duanping1920 2015-12-08 15:09
浏览 25
已采纳

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?

  • 写回答

1条回答 默认 最新

  • douhuan1380 2015-12-08 15:16
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?