2015-03-02 31 views
0

我在MySQL中分組日期時遇到問題。無效的參數號不允許在PDO MySql問題使用分組時

下面是從數據庫中調用我的整個代碼:

// Make todays date 
$todays_date = date('Y-m-d', strtotime('now')) . '00:00:00'; 

// Get all from database and group them by day 
$query = $pdo->prepare("SELECT bookingdate FROM madebookings WHERE bookingdate >= :$todays_date GROUP BY DATE_FORMAT(bookingdate,'%b, %d %Y')"); 
$query->execute(array(':todays_date' => $todays_date)); 
$query_number = $query->rowCount(); 

// Lets build the table 
$files_table = ''; 

if ($query_number > 0) { 
    while ($fetch = $query->fetch()) { 
     //get the items needed 
     $bookingdate = $sanitise->justDate(date('Y-m-d', $fetch['bookingdate'])); 
     $dateUrl  = $date('Y-m-d', $fetch['bookingdate']); 

     $files_table .="<tr>";   
     $files_table .= "<td>".$bookingdate."</td>"; 
     $files_table .= "<td><a href='view-day-bookings.php?date=".$dateUrl."' class=\"btn btn-info btn-sm btn-icon icon-left\"><i class=\"entypo-pencil\"></i>Click here to view bookings</a></td>"; 
     $files_table .= "</tr>"; 
    } 
} 

我得到的錯誤是:

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /XXX/XXX/Documents/www/Applications/Controllers/Bookings/group.php on line 8 

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in /XXX/XXX/Documents/www/Applications/Controllers/Bookings/group.php on line 8 

正如你所看到的問題是在執行行,我懷疑它認爲它需要將%b,%d%Y放入預先準備好的聲明中,但我可能會在此錯誤:(

無論如何,任何人都可以告訴我我做錯了什麼嗎?

+0

:todays_date而不是:$ todays_date來源:http://php.net/manual /en/pdo.prepared-statements.php – 2015-03-02 18:37:38

回答

0

我用$代替:本聲明節:現在

WHERE bookingdate >= :$todays_date 

問題被固定:)