Yii and MAMP MySQL throws CDbException

I’m trying to setup a testing server on my local box so I have Yii and MAMP installed. My actual main.php has


'db' => array(

            'connectionString' => 'mysql:host=123.123.166.77;dbname=hch_dev',

            'emulatePrepare' => true,

            'username' => 'dev_user',

            'password' => 'password',

            'charset' => 'utf8',

            'tablePrefix' => '3hch_',

        ),

which is an external dev server. I want PHPUnit to perform on a local MAMP MySQL server so in test.php I have


return CMap::mergeArray(

	require(dirname(__FILE__).'/main.php'),

	array(

		'components'=>array(

			'fixture'=>array(

				'class'=>'system.test.CDbFixtureManager',

			),


				'db' => array(

                'connectionString' => 'mysql:localhost;dbname=hch_test',

                'emulatePrepare' => true,

                'username' => 'root',

                'password' => 'pw',

                'charset' => 'utf8',

                'tablePrefix' => '3hch_',

            ),


		),

	)

);

when running the Unit tests on the external server all is well, as soon as I put in the local testing server I get an errors such as


CDbException : The table "{{news}}" for active record class "News" cannot be found in the database.

Why would this be? The tables are created in both databases…???

I would suggest you to check two things:

  1. do tables from both databases have same prefix

  2. table names can be case sensitive in some systems, so check this too

Yes databases have the same exact structure and naming conventions, in fact I exported one to the other.

I’m having a similar problem with phpunit on a Ubuntu MAMP box. Did you ever solve this one?

Unfortunately not yet… Any luck on your side?

OK I just solved it in my test config file I had


'db' => array(

                'connectionString' => 'mysql:localhost;dbname=hch_test',

                'emulatePrepare' => true,

                'username' => 'root',

                'password' => 'root',

                'charset' => 'utf8',

                'tablePrefix' => '3hch_',

            ),

and it needs to be:


'db' => array(

                'connectionString' => 'mysql:host=localhost;dbname=hch_test',

                'emulatePrepare' => true,

                'username' => 'root',

                'password' => 'root',

                'charset' => 'utf8',

                'tablePrefix' => '3hch_',

            ),

so I was missing host= DUH!!!!