Yii Property "CDbConnection.tableprefix" is not defined.

I’m new to the Yii framework. I created a table named ‘tbl_user’, had set the tablePrefix to ‘tbl_’ in main.php in the ‘db’ array. When I ran the model command from the yii shell script , I got the following:

QQ图片20140415221014
Stack Trace:

1
2
3
4
5
6
7
8
9
10
11
12
13

#0 W:\newwamp\www\shop\framework\YiiBase.php(220): CComponent->__set("tableprefix", "tbl_")
#1 W:\newwamp\www\shop\framework\base\CModule.php(386): YiiBase::createComponent(array("class" =>"CDbConnection","connectionString" => "mysql:host=localhost;dbname=testdrive", "emulatePrepare" => true, "username" => "root", …))
#2 W:\newwamp\www\shop\framework\base\CModule.php(103): CModule->getComponent("db")
#3 W:\newwamp\www\shop\shop\protected\controllers\IndexController.php(7): CModule->__get("db")
#4 W:\newwamp\www\shop\framework\web\actions\CInlineAction.php(49): IndexController->actionIndex()
#5 W:\newwamp\www\shop\framework\web\CController.php(308): CInlineAction->runWithParams(array("r" => "index/index"))
#6 W:\newwamp\www\shop\framework\web\CController.php(286): CController->runAction(CInlineAction)
#7 W:\newwamp\www\shop\framework\web\CController.php(265): CController->runActionWithFilters(CInlineAction, array())
#8 W:\newwamp\www\shop\framework\web\CWebApplication.php(282): CController->run("index")
#9 W:\newwamp\www\shop\framework\web\CWebApplication.php(141): CWebApplication->runController("index/index")
#10 W:\newwamp\www\shop\framework\base\CApplication.php(180): CWebApplication->processRequest()
#11 W:\newwamp\www\shop\shop\index.php(15): CApplication->run()

I removed the tablePrefix entry from main.php. When I ran the model command again, it shows what i want, i have wrote var_dump(Yii::app()->db); in IndexController.php. it worked!

object(CDbConnection)[13] public ‘connectionString’ =>string‘mysql:host=localhost;dbname=testdrive’(length=37)public* ‘username’ =>string‘root’*(length=4)*public ‘password’ =>string‘528126’*(length=6)public* ‘schemaCachingDuration’ =>int0public ‘schemaCachingExclude’ =>*array(size=0)empty*public ‘schemaCacheID’ =>string‘cache’*(length=5)*public ‘queryCachingDuration’ =>int0public ‘queryCachingDependency’ =>nullpublic ‘queryCachingCount’ =>int0public ‘queryCacheID’ =>string‘cache’*(length=5)*public ‘autoConnect’ =>booleantruepublic ‘charset’ =>string‘utf8’*(length=4)public* ‘emulatePrepare’ =>booleantruepublic ‘enableParamLogging’ =>booleanfalsepublic ‘enableProfiling’ =>booleanfalsepublic ‘tablePrefix’ =>nullpublic ‘initSQLs’ =>nullpublic ‘driverMap’ =>*array(size=9) ‘pgsql’ =>string‘CPgsqlSchema’(length=12) ‘mysqli’ =>string‘CMysqlSchema’(length=12) ‘mysql’ =>string‘CMysqlSchema’(length=12) ‘sqlite’ =>string‘CSqliteSchema’(length=13) ‘sqlite2’ =>string‘CSqliteSchema’(length=13) ‘mssql’ =>string‘CMssqlSchema’(length=12) ‘dblib’ =>string‘CMssqlSchema’(length=12) ‘sqlsrv’ =>string‘CMssqlSchema’(length=12) ‘oci’ =>string‘COciSchema’*(length=10)public* ‘pdoClass’ =>string‘PDO’*(length=3)private* ‘_attributes’ =>*array(size=0)emptyprivate* ‘_active’ =>booleantrueprivate ‘_pdo’ =>object(PDO)[14] private ‘_transaction’ =>nullprivate ‘_schema’ =>nullpublic ‘behaviors’ =>*array(size=0)**empty*private ‘_initialized’ (CApplicationComponent)=>booleantrueprivate ‘_e’ (CComponent)=>nullprivate ‘_m’ (CComponent)=>null

Any idea why I encountered this?

Here’s what I have in main.php.

'db'=>array(  
 'class=>'CDbConnection',  
 'connectionString' => 'mysql:host=localhost;dbname=testdrive',  
 'emulatePrepare' => true,  
 'username' => 'root',  
 'password' => '528126',  
 'charset' => 'utf8',  
 'tableprefix' => 'tbl_',  
 ),```

Yii Property "CDbConnection.tableprefix" is not defined.

https://ldsun.com/2014/04/15/Yii-Property-CDbConnection-tableprefix-is-not-defined/

Author

Ludis

Posted on

2014-04-15

Updated on

2014-04-15

Licensed under

Comments