I have trouble with date data type.
I have a php mysql pdo statement:
$mystmt = $mydb->prepare("
SELECT `ad_id`
FROM `tbl_actions`
WHERE
(`actiondate` > :nowcookietime )
");
$mystmt->execute(array(
':nowcookietime'=>date("Y-m-d H:i:s", time()-$cookiedurationlock),
)
);
$testnotinsql = $mystmt->fetch(PDO::FETCH_ASSOC); // EMPTY
The code run return empty. But if i get the sql below from general_log and run in sql tool (HeidiSQL), it will return record.
SQL from general_log:
SELECT ad_id
FROM tbl_actions
WHERE
(actiondate> '2012-08-24 17:53:21' )
My PHP timezone is UTC+7
Mysql is SYSTEM (which UTC)
As I understand it’s not timezone problem if insert and query in php using same timezone.
I test the bind parameter with force string
':nowcookietime'=>date("Y-m-d H:i:s", time()-$cookiedurationlock),
but it’s same empty.
BUT: if use quote then it return rows
':nowcookietime'=>"'".date("Y-m-d H:i:s", time()-$cookiedurationlock)."'",
Can you clarify what wrong with this statement as I understand we dont need quote, mysql pdo quote for us.
EDIT 1:
I update the correct sql. With quote in sql is my mistake when take from test. The without quote around :nowcookietime stil empty.
CLOSED
See my answer below.
I find out why.
actiondate> ‘\’2012-08-25 02:28:22\” ), so it will return rows.I think I have to organize my script to simpler ones.
Thanks all for your help.