I am attempting to query time data from MySQL in PHP, using this sort of method:
SELECT UNIX_TIMESTAMP( DATE_ADD( a.`date_time`, INTERVAL 1 DAY ) ) * 1000 AS time FROM `graph_values` AS a
On a production server running MySQL 5.0.x, this returns a unix timestamp as expected. However, on a development server running MySQL 5.5.x it returns a string "%qd". I attempted to CAST the result to an unsigned integer following some of the suggestions in the MySQL documentation on this page:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp
When I cast the result of the UNIX_TIMESTAMP function as an UNSIGNED, the query returned a different string, "%qu".
So, its obvious that the odd string is influenced by datatype of the data being returned, but I’ve never seen PHP/MySQL behave this way.
Note: This is using PHP and mysqli.
Any suggestions?
Have you tried casting the result to some other type (signed int, decimal)?
If everything goes wrong – you may be able to use something like FROM_UNIXTIME(UNIX_TIMESTAMP(), ‘%s’);
to “cast” it in another way.
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_from-unixtime
Not something I would want to have in my production code though…