duanping1920
duanping1920
2015-12-08 15:09

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 douhuan1380 6年前

    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);
    
    点赞 评论 复制链接分享