PHP warning Attempt to assign property of non-object

Hi, all.

I’m now trying to use “CSqlDataProvider”, but I’ve got some database connections. like


                        'connectionString' => 'mysql:host=;dbname=test',

                        'emulatePrepare' => true,

                        'username' => 'test',

                        'password' => 'test',

                        'charset' => 'utf8',

                        'class' => 'CDbConnection',


.. more db components ..

I would like to code my controller like this:


                $count=$connection->createCommand('SELECT COUNT(idx) FROM mytable')->queryScalar();

                $sql='SELECT * FROM mytable';

                $dataProvider=new CSqlDataProvider($sql, array(












                $this->render('index', array('dataProvider'=>$dataProvider)); 

It has no problem before redering view


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




When calling method like $dataProvider->getData(); I’ve got an error message.

[color="#FF0000"]Attempt to assign property of non-object[/color] at the code [color="#FF0000"]"$db->active=true;"[/color]

It seems that my $db instance does not have "active" member field. How come???

I found an answer. I’m such a stupid. :-[

It must be ‘db’=>$connection; not ‘db’=>‘db2’.

I passed string instead of instance.