CGridView

Hi Everyone,

I’m fairly new to yii and can’t figure this out. The view code below works great until it encounters a last name with an apostrophe like “D’Alessandro”. As soon as it does, it throws the error.

I’ve tried using ‘value’=>‘addslashes($model->last_name)’, value=> with str_replace but nothing works.

Any suggestions would be greatly appreciated.

Thanks, Bill

Error: 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 ‘Alessandro’ and emp_id = ‘2059’’ at line 1

$CertEmpList = Yii::app()->db->createCommand('SELECT * FROM CertifiedEmployees WHERE contractor = ' . Yii::app()->session['cidCert']. ' ORDER BY last_name, first_name')->queryAll();





$dataProvider=new CArrayDataProvider($CertEmpList, array(


    'id'=>'CertEmp',


    'keyField'=>'id',


    'pagination'=>array(


        'pageSize'=>10,


    ),


));





$this->widget('zii.widgets.grid.CGridView',


    array(


        'id'=>'employees-grid',


        'dataProvider'=>$dataProvider,         


        'filter'=>$model,


        'columns'=>array(


            array(


                'header'=>'First Name',


                'name'=>'first_name',


            ),


            array(


                'header'=>'Last Name',


                'name'=>last_name,


            ),


        


        ),


    )


);