CDbConnection failed on MAMP, MySQL, OS/X


i am new into Yii so this error might to be fixed easy.

After opening the app in the shell i tried to create a model with "model User". Of course i have a table named User in my database… The error seems to occur befor:

Yii Interactive Tool v1.1 (based on Yii v1.1.3)

Please type 'help' for help. Type 'exit' to quit.

>> model User

exception 'CDbException' with message 'CDbConnection failed to open the DB connection: invalid data source name' in /framework/db/CDbConnection.php:269

Stack trace:

#0 /framework/db/CDbConnection.php(242): CDbConnection->open()

#1 /framework/db/CDbConnection.php(221): CDbConnection->setActive(true)

#2 /framework/base/CModule.php(363): CDbConnection->init()

#3 /framework/base/CApplication.php(391): CModule->getComponent('db')

#4 /framework/cli/commands/shell/ModelCommand.php(260): CApplication->getDb()

#5 /framework/cli/commands/ShellCommand.php(144): ModelCommand->run(Array)

#6 /framework/cli/commands/ShellCommand.php(99): ShellCommand->runShell()

#7 /framework/console/CConsoleCommandRunner.php(62): ShellCommand->run(Array)

#8 /framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)

#9 /framework/base/CApplication.php(135): CConsoleApplication->processRequest()

#10 /framework/yiic.php(33): CApplication->run()

#11 /framework/yiic(15): require_once('/...')

My config looks like this:


			'connectionString' => 'host=localhost;dbname=stako;port=8889',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => 'root',

			'charset' => 'utf8',


Thanks for your help in advance…


It cannot connect to the database…

As it says invalid data source name… check if you database name is "stako"… and that mysql is on port 8889

Actually there is a db named stako and port 8889 is also correct… but i think i found the mistake. since i am working in the shell it might use the preinstalled apache/mysql/php from os/x instead of using mamp!? am i right?

I could make it! It was exactly the failure i was guessing in the post befor!

Thanx a lot… Hopefully i can make the next steps now :)

Hi bungalo,

I am having the same issue. Would you mind describing how you fixed it?

I’ve been trying to fix it for a while and I am going crazy… (sorry I am a noob… :-[ )