Cdbcommand Issues

Hi all, I am trying to query a relationship between two tables in my database. I am matching a user_id in a table called property with the user_id in the user table. The SQL command should be SELECT COUNT() FROM tbl_property WHERE user_id=. I am getting an error of the following: 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 ‘’ at line 1. The SQL statement executed was: SELECT COUNT() FROM tbl_property t WHERE user_id=

Posted below is my code:

Property Model:

public function getUserAssignedProperty()


            return new CActiveDataProvider($this, array(




                            'order'=>'property_id DESC'





Hand Receipt View:


$this->beginWidget('bootstrap.widgets.TbBox', array(

    'title' => 'Hand Receipt',

    'headerIcon' => 'icon-home',

    'htmlOptions' => array('class'=>'bootstrap-widget-table'),



)); ?>

<?php echo $this->renderPartial('_handReceipt',array('model'=>$model, 'provider'=>$model->getUserAssignedProperty())) ?>

<?php $this->endWidget();?>

Right now I don’t have anything in _handReceipt as it isn’t making it that far. Any help would be awesome. Thanks. :rolleyes:

Are you setting up the user_id session variable correctly in WebUser.php?

Im not using the WebUser component.

Problem resolved. I had to setup this in UserIdentity. You were right JFReyes:


Glad that you solved the problem. :)

I mentioned WebUser because another way of doing it that doesn’t require sessions is as a property of the user object. Then you can access it as Yii::app()->user->user_id.