phpunit test ok but gii issue on MAMP

OS X 10.6.7

MAMP 1.9.6

Apache/2.0.64 (Unix) PHP/5.3.5 DAV/2 Yii Framework/1.1.7 2011-04-25

I’m new to php, yii, mysql.

I’m working my way through the yii book by Jeffrey Winesett.

I have a phpunit test that succeeds but gii fails.

I can login to gii. I can see the 5 bullet menu. Controller Generator, Form Generator, Module Generator menu choices yield another html page but…

Crud Generator and Model Generator produce this error:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2003] Can’t connect to MySQL server on ‘localhost:8889’ (4)

Specifically at line 52 in


and it looks like this:


<minor query> not sure why there are 3 equal signs in the code above.</minor query>

my phpunit test that succeeds:


class DbTest extends CTestCase


public function testConnection()



	// is the db connection alive?

	&#036;this-&gt;assertNotEquals(NULL, Yii::app()-&gt;db);

	&#036;this-&gt;assertNotEquals(false, Yii::app()-&gt;db-&gt;active);



	// now for table name analysis

	&#036;ar = Yii::app()-&gt;db-&gt;getSchema()-&gt;getTableNames();

	&#036;this-&gt;assertNotEquals(NULL, &#036;ar);

	&#036;this-&gt;assertEquals( 'tbl_project', &#036;ar[0]);	}


any assistance would be gratefully received. Please be explicit about file locations and versions. TIA.

OK, solved…

When you bring up the MAMP start page it says MySQL is running on port 8889. So when I removed the port number from my connection string above gii can connect to my MySQL instance.

The 3 equal signs check that the datatype is also the same. Meaning it also checks that for example both the values are an integer.

Thanks EdoFre!

Also, I have found that entering the following in /etc/php.ini that phpunit can connect to the MAMP MySQL instance:


I’m not sure why it works but it seems to. Yeah, I know the two environments snow leopard CLI and MAMP aren’t exactly the same but at least I can move forward with the rest of the book until the next issue pops up. :)