Yii Framework Forum: Gii Model Generator - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Gii Model Generator A valid database connection is req... Rate Topic: ****- 1 Votes

#1 User is offline   SquareDot 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 14-April 13

Posted 14 April 2013 - 03:32 PM

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:
A valid database connection is required to run this generator. 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
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 15 April 2013 - 01:23 AM

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?
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   SquareDot 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 14-April 13

Posted 15 April 2013 - 02:46 AM

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 A valid database connection is required to run this generator.

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
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 15 April 2013 - 03:09 AM

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 ?
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   SquareDot 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 14-April 13

Posted 15 April 2013 - 03:48 AM

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

leaving db produce models\TblUser.php
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users