2014-10-29 47 views
0

下面的查詢工作MySQL的函數IF(DAY(customers_dob)= DAY(CURRENT_DATE),真,假)AS今天不與PDO

$stmt = $db->query(" 
    SELECT CONCAT(customers_firstname, ' ', customers_lastname) name, 
      customers_dob AS dob, 
      IF(DAY(customers_dob) = DAY(current_date), true, false) AS today, 
      IF(MONTH(customers_dob) = MONTH(current_date), true, false) AS month, 
      YEAR(current_date) - YEAR(customers_dob) AS year 
    FROM  " . TABLE_CUSTOMERS . " 
    WHERE MONTH(customers_dob) = MONTH(current_date) 
    AND  DAY(customers_dob) >= DAY(current_date) 
    ORDER BY customers_dob 
"); 
$birthdays = $stmt->fetchAll(); 

正常工作與mysql擴展在PHP和它給導致phpMyAdmin。

隨着PDO我只得到這個數組

Array 
(
    [name] => Max Mustermann 
    [0] => Max Mustermann 
    [year] => 44 
    [1] => 44 
) 

「今天」和「月」密鑰丟失。

我該怎麼做?

+0

「'ers_lastname)name'」 缺少'AS'。你也沒有得到'dob' – 2014-10-29 21:39:25

+0

首先將你的例子縮減爲失敗的單例。在問答網站上詢問其他問題無關緊要。另外清楚地說明你正確地進行了錯誤檢查以及你正在使用的SQL模式。 – hakre 2014-10-29 21:47:00

回答

0

您不會混淆名字和姓氏的拼接 - 您錯過了AS關鍵字。變化:

SELECT CONCAT(customers_firstname, ' ', customers_lastname) name, 

到:

SELECT CONCAT(customers_firstname, ' ', customers_lastname) AS name,