2014-12-08 115 views
1

我想算新註冊會員,但我有麻煩PDO盤點記錄與當前日期

$time = new DateTime(); 
    $currentdate = $time->format('Y-m-d'); 


    $cmd=$con->query("select count(*) from user where date(datereg) = ?"); 
    $cmd->execute($currentdate); 
    $rowcount = $cmd->fetchColumn(); 

    echo $rowcount; 

預先感謝您。

+1

爲什麼不只是使用NOW()函數 – user3815506 2014-12-08 02:21:34

回答

1

在您的查詢中放置一個佔位符沒有意義,因爲您沒有準備它。

$cmd=$con->query("select count(*) from user where date(datereg) = ?"); 
     //^query not prepare 

$cmd->execute($currentdate); // execute? $cmd is not prepared 

裏面只需創建一個正常的查詢:在MySQL

$sql = 'SELECT COUNT(*) AS `count` FROM user WHERE DATE(datereg) = CURDATE()'; 
$result = $con->query($sql); 
$count = $result->fetchColumn();