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

FIX

http://www.apachefri…hp?f=16&t=32617

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

UPDATE

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


		'db'=>array(


			//'connectionString'=>'sqlite:protected/data/test.db',


			'class'=>'CDbConnection',


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


    	'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();

CRASH

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:

    D:\xampp\htdocs\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);

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.

http://www.yiiframew…start.first-app

% 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:


    D:wwwroottestdriveprotectedmodelsUser.php





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


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


    print_r($model);





>> 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:


http://hostname/path/to/index.php?r=user


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.

regards,

zahid mughal