Mysql Connection Error

I’m using Yii for the first time so please excuse the novice question I’m about to ask.

I’m following the steps in setting up my Yii application, and have encountered the following error in connecting to the database:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '' (13)

Here are the parameters I’ve set up for the db array:


	'connectionString' => 'mysql:host=;port=3306;dbname=Sandbox;',

	'emulatePrepare' => true,

	'username' => 'username',

	'password' => 'password',

	'charset' => 'utf8',


I have changed the array on main.php and console.php. I’ve tried it with/without the “unix_socket” parameter as well with no luck.

I’m lost on what to try next. Any help is appreciated.

That’s not really a novice question. Yii/PHP seems to be unable to connect to your MySQL server. Check if that IP is really correct. Also, see here.

Thanks for the response. I’ll review your link. I’m positive thats the IP address (I have other applications connecting to it)

if ip is correct. try to make sure your dbname, username and password are correct as well. are you using any configurations files in your config folder other than main.php(may be unknowingly you are overwriting the db array in main.php)??


larryullman’s Introduction to the Yii Framework this is really useful for beginners

That would result into error messages very different from what has been posted here. Something must be hampering connectivity at a lower level.

Have you tried to setup a local database and connect to or localhost to make sure that it isn’t a PDO problem?

Also it would be useful if you have a local MySQL client and could tell us if

mysql -h -u root -p

is working.

Are you sure that is correct and you did not meant (I guess the first IP address is from your router)

I too have this exact same problem.

I can connect using the Yii framework to my localhost mysql database using xampp

I can connect to my mysql database (on a linux server on Godaddy), using normal php connectionstring.

But when I use the connectionstring in the Yii Framework and do the recommended tests, it doesn’t work inside the framework.

This works:


		'connectionString' => 'mysql:host=;port=3306,dbname=cmi',

		'emulatePrepare' => true,

		'username' => 'root',

		'password' => '',

		'charset' => 'utf8',


This connectionstring works in my normal (no framework) way.

$con = mysql_connect("", "smucmap", "XXXXXX") or die("Could not Connect to MySQL server!");

This does not work:


		'connectionString' => 'mysql:host=;port=3306,dbname=smucmap',

		'emulatePrepare' => true,

		'username' => 'smucmap',

		'password' => 'XXXXX',

		'charset' => 'utf8',


Does anything else need to be changed when switching from a local database to using one out in the cloud?

Have you tried with ‘connectionString’ => ‘mysql:host=localhost,dbname=smucmap’ ?

This works for me: ( also use godaddy host)


		'connectionString' => 'mysql:host=; port=3306;dbname=soccer_tips',

		'emulatePrepare' => true,

		'username' => 'soccer',

		'password' => '*****',

		'charset' => 'utf8',