problems getting Yii to work with MySQL

Hi guys,

I'm having some trouble getting Yii to work with MySQL on my MAMP box. I have in my main.php:

'db'=>array(

                        'class'=>'CDbConnection',

                        'connectionString'=>'mysql:localhost;dbname=testdb;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock',

                        'username'=>'username',

                        'password'=>'password',

                ),

Then I run:

/Applications/MAMP/bin/php5/bin/php …/yii/framework/yiic shell

I type: model User

And I get:

>> model User

Warning: the table 'User' does not exist in the database.

  unchanged User.php

When trying crud User I get:

>> crud User

exception 'CDbException' with message 'The table "User" for active record class "User" cannot be found in the database.' in /Applications/MAMP/htdocs/yii/framework/db/ar/CActiveRecord.php:1569

Stack trace:

#0 /Applications/MAMP/htdocs/yii/framework/db/ar/CActiveRecord.php(436): CActiveRecordMetaData->__construct(Object(User))

#1 /Applications/MAMP/htdocs/yii/framework/cli/commands/shell/CrudCommand.php(102): CActiveRecord::model('User')

#2 /Applications/MAMP/htdocs/yii/framework/console/CConsoleCommand.php(116): CrudCommand->generateController('/Applications/M…', Array)

#3 /Applications/MAMP/htdocs/yii/framework/cli/commands/shell/CrudCommand.php(93): CConsoleCommand->copyFiles(Array, '/Applications/M…', Array)

#4 /Applications/MAMP/htdocs/yii/framework/cli/commands/ShellCommand.php(98): CrudCommand->run(Array)

#5 /Applications/MAMP/htdocs/yii/framework/cli/commands/ShellCommand.php(78): ShellCommand->runShell(Array)

#6 /Applications/MAMP/htdocs/yii/framework/console/CConsoleCommandRunner.php(62): ShellCommand->run()

#7 /Applications/MAMP/htdocs/yii/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)

#8 /Applications/MAMP/htdocs/yii/framework/base/CApplication.php(146): CConsoleApplication->processRequest(Array)

#9 /Applications/MAMP/htdocs/yii/framework/yiic.php(30): CApplication->run()

#10 /Applications/MAMP/htdocs/yii/framework/yiic(15): require_once('/Applications/M…')

#11 {main}

MySQL is up and running and I have a database named testdb with a table User created like this:

CREATE TABLE testdb.User (

id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,

username VARCHAR( 128 ) NOT NULL ,

password VARCHAR( 128 ) NOT NULL ,

email VARCHAR( 128 ) NOT NULL

) ENGINE = MYISAM

Can anyone tell me why it's not working?

The connection string format is like this:



'connectionString'=>'mysql:host=localhost;dbname=Yii','username'=>'user', 'password'=>'pw', 'charset'=>'utf8',


/Tommy

Thanks!  :D

Hi folks, I'm new here and I am trying to work my way through the example app.

I created a MySql data base but I don't seem to be able to connect to it.

This is in …/testdrive/config/main.php

'db'=>array(


            'class'=>'CDbConnection',


            'connectionString'=>'mysql:host=localhost;dbname=yii','username'=>'xxx','password'=>'xxx','charset'=>'utf8','emulatePrepare'=>true,


        ),

yiic gives the following message when issued command "model User"

Quote

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

and "$model=User::model()->find();" gives the following warning

Quote

exception 'CDbException' with message 'Active Record requires a "db" CDbConnecti

on application component.' in C:\xampp\htdocs\yii\framework\db\ar\CActiveRecord.

php:582

Stack trace:

#0 C:\xampp\htdocs\yii\framework\db\ar\CActiveRecord.php(622): CActiveRecord->ge

tDbConnection()

#1 C:\xampp\htdocs\yii\framework\db\ar\CActiveRecord.php(1049): CActiveRecord->g

etCommandBuilder()

#2 C:\xampp\htdocs\yii\framework\cli\commands\ShellCommand.php(101) : eval()'d c

ode(1): CActiveRecord->find()

#3 C:\xampp\htdocs\yii\framework\cli\commands\ShellCommand.php(101): eval()

#4 C:\xampp\htdocs\yii\framework\cli\commands\ShellCommand.php(78): ShellCommand

->runShell()

#5 C:\xampp\htdocs\yii\framework\console\CConsoleCommandRunner.php(62): ShellCom

mand->run(Array)

#6 C:\xampp\htdocs\yii\framework\console\CConsoleApplication.php(88): CConsoleCo

mmandRunner->run(Array)

#7 C:\xampp\htdocs\yii\framework\base\CApplication.php(146): CConsoleApplication

->processRequest()

#8 C:\xampp\htdocs\yii\framework\yiic.php(30): CApplication->run()

#9 C:\xampp\htdocs\yii\framework\yiic(15): require_once('C:\xampp\htdocs…')

#10 {main}

Any idea where I should look next?

doodle

If you make any change to the config file, make sure you exit yiic shell and re-enter it so that the new change can take effect.

OK thanks, I really don't know what I did but it works now.  Probably at some point I did exit yiic shell.

Growing pains!

doodle

Hi

Anyone has tried connecting mssql server…? I have same error but it is sure that i had enabled php.ini with extenstion pdo_** and ext=mssql enabled…

Anyone has idea… pls help

Regards

Dhana

ActiveRecord currently only supports sqlite, mysql and pgsql.

If you could write an AR driver for mssql, please let us know (you may refer to drivers under framework/db/schema).

Hi,

Thanks for your quick response… Yii is very user friendly… and if it has mssql driver, then companies like us having legacy application running with SQL server would get a chance to change over to web application easily.

Yes I want to try ActiveRecrod driver for Mssql.

your help or guidence to that would be appreciated

Regards

dhana

That's cool. You may refer to the mssql implementation in Prado:

http://code.google.c…a/Common/Mssql/

I'm interested in getting Oracle support, so I'll check out the driver for Oracle. I'm assuming the Oracle implementation in Prado would be a good starting point as well?

Yes.

Hello everyone. Im trying to build a Blog system using Yii, when I generate a model using Yii shell "/wwwroot/yiiblog/framework/yiic shell /wwwroot/yiiblog/index.php" and when I write >>model user, I have an error message :

exception ‘CDbException’ with message ‘CDbConnection failed to open the DB connection: SQLSTATE[42000] [1049] unknow database’ yiiblog’’ in c:\xampp\htdocs\yiiblog\framework\db\CDbConnection.php:248

do you have any idea? I’ve been create “yiiblog” database and /wwwroot/blog/protected/config/main.php

‘db’=>array(

'class'=>'CDbConnection',


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


'username'=>'root',


'password'=>'mypassword'


),

do you have any idea? thanks

I think your connectionString, dbname=yiiblog, no space between = and yiiblog.

Hello, what tool you use for to do de database.

I have a mysql connection, but this not work.

Helpme please!!