Gii Model Generator

Hello

I’ve searched the forum but didnt find a solution so here my question.

I got yii on Uniform Server. Mysql db (name=mynewdb) .

I checked requirements and i got mysql pdo eanbled.

I want to use mysql instead of sqllite so i changed settings in:

protected/config/main.php

protected/config/console.php

commenting sqlite row and uncommenting and changing those of mysql




'db'=>array(

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

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => 'root',

			'charset' => 'utf8',

		),



when i try to use gii model generator i get a:

[color="#FF0000"]A valid database connection is required to run this generator[/color]. error

if i put in the same folder as my web application a php page to check db connection (the one below) i could connect to my db and retrieve data with no problem




try{

    $dbh = new pdo( 'mysql:host=localhost;dbname=mynewdb',

                    'root',

                    'root',

                    array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

					

$statement = $dbh->prepare("select id from tbl_user where username = :name");

$statement->execute(array(':name' => "test"));

$row = $statement->fetch(); 

    echo "requested id $row[0]";

	die(json_encode(array('outcome' => true)));

}

catch(PDOException $ex){

    die(json_encode(array('outcome' => false, 'message' => 'Unable to connect')));

}



What i’m doing wrong? thankyou alot in advance for any help

Hi and welcome to the Yii forum.

When do you get this error, what do you open/click/write/… to get this error ?

I can only guess it’s on the model generator page when you enter a table name and click on “preview”?

If that is right check the first filed under "Database Connection" there should be "db", do you have something else there or maybe enter something else there?

Hello Maurizio.

yes you guess are right.

The error comes from model generator page when i press preview button.

I complete

database connection field with my db name (mynewdb),

table namefield with my allready existing table (tbl_user)and i get autocomplete on model class field,

then i hit preview button and i get [color="#FF0000"]A valid database connection is required to run this generator.[/color]

Another thing that confuse me is that i still can access my web application login using default accounts (admin-admin or demo-demo) even after i commented sqlite rows.

I tough that those accounts where stored in sqlite but i still have not checked this so i should be wrong

The demo/demo, admin/admin is hardcoded that’s why it’s working…

So you change the database connection to "mynewdb" but that is your database name not your database connection.

From your initial post, your database connection is "db"… and that field is automatically prepopulated with it… did you try leaving it like that ?

Maurizio thankyou so much! I really appreciate you wasted your time to teach me something

leaving db produce models\TblUser.php