Dates in PHP and MySQL
I am tr开发者_C百科ying to use following queries but the browser says Fatal error: Call to undefined function FROM_UNIXTIME()
$query = "UPDATE table
SET datetimefield = FROM_UNIXTIME($phpdate)
WHERE...";
$query = "SELECT UNIX_TIMESTAMP(datetimefield)
FROM table
WHERE...";
I am following http://www.richardlord.net/blog/dates-in-php-and-mysql
You cannot use a database function on a PHP variable. Try this:
$query = "UPDATE table
SET datetimefield = FROM_UNIXTIME(" . strtotime($phpdate) . ")
WHERE...";
$query = "SELECT UNIX_TIMESTAMP(datetimefield)
FROM table
WHERE...";
精彩评论