count problem


I’m playin with Yii, and I have rly strange issue and I can’t fugure it out.

Im trying to count some rows in my db table.

code im using is:

Messages::model()->count('recipient_id=:myself AND sender_id=:sender_id AND read=:read_state', array(':myself' => Yii::app()->user->id, ':sender_id'=>$senderId, ':read_state' => 0))

and result is:

CDbCommand failed to execute the SQL statement: 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' at line 1. The SQL statement executed was: SELECT COUNT(*) FROM `messages` `t` WHERE recipient_id=:myself AND sender_id=:sender_id AND read=:read_state

my simple DB table looks like that:

'id', 'int(10) unsigned', 'NO', 'PRI', '', 'auto_increment'

'sender_id', 'int(10) unsigned', 'NO', '', '', ''

'recipient_id', 'int(10) unsigned', 'NO', '', '', ''

'data', 'text', 'NO', '', '', ''

'date_added', 'datetime', 'NO', '', '', ''

'read', 'tinyint(1)', 'NO', '', '0', ''

Anyone has any idea what is going on?


Have a look here


Qualify field read as

reserved word.


			'recipient_id=:myself AND sender_id=:sender_id AND', 

			array(':myself' => Yii::app()->user->id, ':sender_id'=>1, ':read_state' => 0));

like a charm… thanks guyz