Very strange... New D7 database object api, wow, so cool, so good. No, I will not go to RoR. I love drupal.
I like to use column names that is reserved in mysql, like `read`, `from`, it is very easy.
Before Drupal I always used it, and OF COURSE put into `` quotes, like phpMyAdmin does.
But now how to be?
$q=db_select('apimsg', 'a');
$q->fields('a',array('id','from','msg','created'));
$q->addExpression('(select name from users where uid=a.uid limit 1)','name');
$q->condition('uid',$uid);
$q->condition('read','0');
TWO Pdo Exceptions.
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You
have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'from, a.msg AS msg,...
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You
have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'read = '0')' ...
It is one more reason to use db_query, that is really more easy. I understand, you doing it for compatibility with other dbs...
I don't have ability to change column names, they are used by other app.
Aliases also need to be escaped....
Comments
Comment #1
swentel commentedYou should never ever use reserved keywords. Period.