Problems with model command [FIX, it was MySQL related]



The entire problem is due to an error in XAMPP 1.7 Replaced the mysql dll and things finally work.


Biting the bullet I followed the example completely and used an SqLite database. It worked fine. Switched back to MySQL executing the exact same commands in the shell (I did stop/start the shell to reload the configuration changes) and the command fails by crashing the shell silently.

		// uncomment the following to set up database





    	'username' => 'root',

    	'password' => '',


With sqlite enabled it works as documented in the tutorial.

With mysql enabled it crashes after the command "model User user generate User.php" or "model User" or "model User user" or "crud User".

I added the class part later as some forums posts suggest this. With or without the same result. I can execute regular "mysql_connect"statements from the shell and they work fine.

>> $connection = new CDbConnection("mysql:host=localhost;dbname=dutchbox","root"


>> $connection->active=true

>> $command=$connection->createCommand("select * from user");

>> $dr = $command->query();


I think therefor there is something wrong with my database. As you can see I resorted to connecting to mysql's own internat database in case something was wrong with the one I created but the same thing happens.

I am trying to follow the tutorial but am stuck on the bit where you have to use the modal command in the shell to create some php based on your database scheme.

I am using mysql instead of SQLite but have corrected the db connection paramater as documented in the comments.

The problem is that the command given doesn't seem to work. The "help model" hint seems outdated as it only mentions 2 parameters.

The command is supposed to be "model User generate User.php" I presume on ONE line (very unclear if this is the case from the documentation.  However the inline help suggests "model classname tablename". I have tried various combo's.

>> model User generate User.php

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

      exist User.php

            …overwrite? [Yes|No|All|Quit] y

  overwrite User.php

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


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



What table generate? Isn't that the command? Leaving it out doesn't work.

What exactly is the command to execute? I have tried multiple variations and just can't figure it out.

Where did you learn the syntax "model User generate User.php"?

The command should be either "model User" or "model User user-table-name". The latter is needed if the table name is different from the class name.


% cd WebRoot/testdrive

% YiiRoot/framework/yiic shell

Yii Interactive Tool v1.0

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

>> model User

   generate User.php

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


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



>> crud User

   generate UserController.php

   generate create.php

      mkdir D:/wwwroot/testdrive/protected/views/user

   generate update.php

   generate list.php

   generate show.php

Crud 'user' has been successfully created. You may access it via:


This is what I am trying to follow.

>> model user

Druk op een toets om door te gaan. . .

Same result for model user user

As long as the database name exists I am dumped back to the command line. If the database name doesn't exist "model user DOESNOTEXIST" a php file is generated, just with the wrong database name.

If your table name is 'user' (all lower case), then you should use "crud User user" command.

Just wanted to say that I encountered this same problem and the fix worked great so thanks! Just a note make sure to replace the libmysql.dll in BOTH apache/bin and xammp/php

Hi, brother listen , when you run the shell and after it you have put the command like "model user", it will automatically create your database table information in the"D:\xmp\xampp\htdocs\New Folder\blog1\protected\views" folder, so after it you can change it according to your requirements. For this you should have a database connection with config/main.php file. After it you can run CRUD command. Without database connection your CRUD command will not work.

if there is some difficulty remain you can ask it again.


zahid mughal