db connection string

i'm running yii on a mampstack environment. I have to specify where is located the sock file because it is not a standard location.



// uncomment the following to set up database


'db'=>array(


	'connectionString'=>'mysql:host=localhost;dbname=testdrive;unix_socket=/Applications/mampstack-1.0/mysql/tmp/mysql.sock',


	'username'=>'root',


	'password'=>'password'


		),


when i launch YiiRoot/framework/yiic shell WebRoot/testdrive/index.php and create the first model User yiic returns an exception :

'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /Applications/mampstack-1.0/apache2/htdocs/dev/yii/framework/db/CDbConnection.php:228

where am i wrong?

Do you have MySQL PDO driver enabled?

What if you try the following code in a test script?



$pdo=new PDO('mysql:host=localhost;dbname=testdrive;unix_socket=/Applications/mampstack-1.0/mysql/tmp/mysql.sock', 'root','password');


it fetches records correctly.

all i can see is that i run shell then i type model user and it returns the error. i re-type model user and the class file is created correctly. it says

Warning: you do not have a 'db' database connection as required by Active Record.

  generate user.php

The 'user' class has been successfully created in the following file:

    /Applications/mampstack-1.0/apache2/htdocs/dev/testdrive/protected/models/user.php

If you have a 'db' database connection, you can test it now with:

    $model=user::model()->find();

    print_r($model);

but if i try what it suggests :

Active Record requires a "db" CDbConnection application component

Make sure you re-enter yiic shell each time you change the config.

The error means you do not have the 'db' component specified in the config.

which config?

main.php or console.php?

main.php

ok, i'm right than.

the FIRST error it returns is '…could not find driver…' but i'm sure i have pdo mysql correctly installed because the test script you suggest before works.

that's probably the most important error.

anyway, if i don't close the shell and retype model user the class is created with the warning but in any of this cases i don't touch the main.php class while in the shell.

WOOOAH!

finally found the trick.

on mac os x, in cli mod do immediately "which php" in termial.

you will see that it is using the php installed by mac os and it doesn't have pdo extension!!

so, if you launch the shell command forcing it to use the php with pdo (in my case " /Applications/MAMP/bin/php5/bin/php")

everything works!

so everytime i have to interact with shell i have to do:

/Applications/MAMP/bin/php5/bin/php yii/framework/yiic shell testdrive/index.php

does anyone knows a way to force this?

glad u found the cause of the issue. I will update the guide to warn this.

Hello ilzale…a little more info that could help you and other out:

A note on PHP and Mac OSX:

A version of PHP4 comes bundled on Mac OSX and is typically what is executed when you try the php command from the command line.  You need to have the php command execute a version of PHP5.x or higher.  Usually, you have already installed a version of PHP5.x or higher, but need to tell the php command to execute the newer version rather than the older one.  There are certainly many ways to achieve this, but here is one:

at any terminal prompt, type in:

prompt>which php

this should tell you where the OS is looking for the php command

mine tells me /usr/bin/php

if I navigate to /usr/bin and issue an ls php I will see three files

php

php-config

phpize

These are all for the bundled version PHP4.x

rename these files to use a 4 in their names, to remember these are the executables for PHP4

mv php php4

mv php-config php-config4

mv phpize phpize4

Then, create sym links for each of these these to point to the PHP5.x or higher version you have installed.  In my case these are located in /usr/local/apache/php/bin.  So I would issue from the /usr/bin directory

ln -s [absolute path to your php5.x] php

and similarly for the other files.

hopes this helps.

To make this easier instead of linking all the php files you can do the following:

Open a terminal window and enter the following commands in your home dir (cd ~):

% pico .profile

paste "# Add MAMP binaries to front of path

PATH=/Applications/MAMP/bin/php5/bin:\

/Applications/MAMP/Library/bin:$PATH

export PATH "

without the quotes

then exit and save

reload the .profile file by doing

% . ./.profile

then you can head over to the yiic interactive tool and you won't have to worry about using the php bin path every time.

Huh!

I had the same issue, and I am working on it since ten hours!, I couldn’t imagine that case!

Thank you ilzale!

Have fun with Yii!

greetings,

Firas