gii * generator

Greetings,

first to mention that I’m NOT sure that this is a bug, fact is that I have a problem when try to use gii.

I’m completely new to yii/gii and using official documentation yii-guide 1.1.4.pdf with few changes, I already have functional mysql database.

I try to comment in host file ::1 localhost line but without success.

When I try gii/model (http://localhost/Examples/Web/yii/testdrive/index.php?r=gii/model) error message appear:

PHP Error

Description

PDO::__construct(): [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:dbname=exampleSchema:3306)

Source File

D:\WebTools\yii-1.1.4.r2429\framework\db\CDbConnection.php(310)

I use windows XP, yii 1.1.4 stable release, Apache 2.2.16, MySQL 5.1.49-community, PHP 5.3.3.

There is a result of yii requirements

Yii Requirement Checker

Description

Name Result Required By Memo

PHP version Passed Yii Framework PHP 5.1.0 or higher is required.

$_SERVER variable Passed Yii Framework

Reflection extension Passed Yii Framework

PCRE extension Passed Yii Framework

SPL extension Passed Yii Framework

DOM extension Passed CWsdlGenerator

PDO extension Passed All DB-related classes

PDO SQLite extension Warning All DB-related classes This is required if you are using SQLite database.

PDO MySQL extension Passed All DB-related classes This is required if you are using MySQL database.

PDO PostgreSQL extension Warning All DB-related classes This is required if you are using PostgreSQL database.

Memcache extension Warning CMemCache

APC extension Passed CApcCache

Mcrypt extension Passed CSecurityManager This is required by encrypt and decrypt methods.

SOAP extension Passed CWebService, CWebServiceAction

GD extension Passed CCaptchaAction

passed 	 	failed 	 	warning

Apache/2.2.16 (Win32) PHP/5.3.3 DAV/2 Yii Framework/ 2010-10-26 12:31

Seems like it cannot connect to the database… what is your connectionString?

Also your error message looks truncated as it says:

"A connection attempt failed because the connected party did not"

‘db’=>array(

‘connectionString’ => ‘mysql:host=localhost:dbname=exampleSchema’,

‘emulatePrepare’ => true,

‘username’ => ‘root’,

‘password’ => ‘root’,

‘charset’ => ‘utf8’,

),

full error message

PHP Error

Description

PDO::__construct(): [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:dbname=exampleSchema:3306)

Source File

D:\WebTools\yii-1.1.4.r2429\framework\db\CDbConnection.php(310)

00298: * @since 1.0.4

00299: */

00300: protected function createPdoInstance()

00301: {

00302: $pdoClass=‘PDO’;

00303: if(($pos=strpos($this->connectionString,’:’))!==false)

00304: {

00305: $driver=strtolower(substr($this->connectionString,0,$pos));

00306: if($driver===‘mssql’ || $driver===‘dblib’)

00307: $pdoClass=‘CMssqlPdoAdapter’;

00308: }

00309: return new $pdoClass($this->connectionString,$this->username,

00310: $this->password,$this->_attributes);

00311: }

00312:

00313: /**

00314: * Initializes the open db connection.

00315: * This method is invoked right after the db connection is established.

00316: * The default implementation is to set the charset for MySQL and PostgreSQL database connections.

00317: * @param PDO the PDO instance

00318: */

00319: protected function initConnection($pdo)

00320: {

00321: $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

00322: if($this->emulatePrepare && constant(‘PDO::ATTR_EMULATE_PREPARES’))

Stack Trace

#0 D:\WebTools\yii-1.1.4.r2429\framework\db\CDbConnection.php(310): PDO->__construct()

#1 D:\WebTools\yii-1.1.4.r2429\framework\db\CDbConnection.php(261): CDbConnection->createPdoInstance()

#2 D:\WebTools\yii-1.1.4.r2429\framework\db\CDbConnection.php(242): CDbConnection->open()

#3 D:\WebTools\yii-1.1.4.r2429\framework\db\CDbConnection.php(221): CDbConnection->setActive()

#4 D:\WebTools\yii-1.1.4.r2429\framework\base\CModule.php(363): CDbConnection->init()

#5 D:\WebTools\yii-1.1.4.r2429\framework\base\CModule.php(86): CWebApplication->getComponent()

#6 D:\WebTools\yii-1.1.4.r2429\framework\gii\generators\model\ModelCode.php(51): CWebApplication->__get()

#7 D:\WebTools\yii-1.1.4.r2429\framework\web\CFormModel.php(40): ModelCode->init()

#8 D:\WebTools\yii-1.1.4.r2429\framework\gii\CCodeGenerator.php(149): ModelCode->__construct()

#9 D:\WebTools\yii-1.1.4.r2429\framework\gii\CCodeGenerator.php(61): ModelGenerator->prepare()

#10 D:\WebTools\yii-1.1.4.r2429\framework\web\actions\CInlineAction.php(50): ModelGenerator->actionIndex()

#11 D:\WebTools\yii-1.1.4.r2429\framework\web\CController.php(300): CInlineAction->run()

#12 D:\WebTools\yii-1.1.4.r2429\framework\web\CController.php(278): ModelGenerator->runAction()

#13 D:\WebTools\yii-1.1.4.r2429\framework\web\CController.php(257): ModelGenerator->runActionWithFilters()

#14 D:\WebTools\yii-1.1.4.r2429\framework\web\CWebApplication.php(324): ModelGenerator->run()

#15 D:\WebTools\yii-1.1.4.r2429\framework\web\CWebApplication.php(121): CWebApplication->runController()

#16 D:\WebTools\yii-1.1.4.r2429\framework\base\CApplication.php(135): CWebApplication->processRequest()

#17 E:\MyDocuments\Projects\Examples\Web\yii\testdrive\index.php(13): CWebApplication->run()

I googled your error and found this:

http://coreygilmore.com/blog/2009/11/20/fix-php-5-3-hang-on-windows/

Ty for quick replay,

I already try that “solution” but without success, also a repeat it now again, and restart comp, but without real solution. Also just to mention that I don’t have installed ip6…

Have you tried the 127.0.0.1 instead of localhost as suggested on the last comment in that post ?

Yes I’m, few times, I changed localhost with 127.0.0.1 in main.php and in browser address.

I try that few days ago, and now again…

From all I read about this error this line should work


'connectionString' => 'mysql:host=127.0.0.1:dbname=exampleSchema',

Other than that… check that mysql is working, that is on port 3306, that is not blocked by a firewall

nothing other comes to mind…

OK ty for your effort, I already try with/without firewall, MySQL workbench connect to database without problem on same port.

I just noticed one thing… in the connectionString the host and the dbname should be separated with a semicolon ( ; ) not with a doublecolon ( : )

Yes, great, ty for help! SOLVED…

Glad we solved it… but it’s strange you are getting that error…

If I put a double colon I’m getting a different error that is more meaningful:

but I’m trying this on linux…

Well that’s how thing stand, I only changed : to ; and now it’s working. Before that I had a error… If I can help somehow please be free to write…

I am using Linux (Ubuntu), and I tried replacing the semicolon with doublecolon and this is what I got: