0

I'm trying to execute the following :

db_query('SELECT FROM_UNIXTIME(`created`, "%Y") as year, FROM_UNIXTIME(`created`, "%m") as month, FROM_UNIXTIME(`created`, "%d") as day FROM users ORDER BY `created`');

And because of the % sign the result is : PDOException : SQLSTATE[42S22]: Column not found: 1054 Unknown column '%Y' in 'field list'

I tried escaping the % with a double %% resulting in : PDOException : SQLSTATE[42S22]: Column not found: 1054 Unknown column '%%Y' in 'field list'

Of course this query works in phpmyadmin

Help ?

0

PDO requires that you use single quotes, e.g.

db_query("SELECT FROM_UNIXTIME(`created`, '%Y') as year, FROM_UNIXTIME(`created`, '%m') as month, FROM_UNIXTIME(`created`, '%d') as day FROM users ORDER BY `created`");
  • 1
    it is waaay to early in the morning for fielding questions i guess :D – tenken Nov 10 '14 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.