Problem with Mysql connection

Hi i am new to yiiframework.

I am trying to create model for my table from mysql

But it has given me the error like this:

Call to a member function getDb() on non object in ModelCommand.php

I also load pdo and pdo_mysql driver.

In main.php the code is:

return array(


   'name'=>'My Web Application',

   // autoloading model and component classes







   // application components



         // enable cookie-based authentication



      // uncomment the following to set up database








Then I do the following things

I try to create small application  demo like testdrive.

I create folder WebRoot .then I create testdrive application through command webapp.

Then I go from command line

cd WebRoot/testdrive/Protected

and type

yiic shell yiic.bat

and then

Yii Interactive Tool v1.0

Please type 'help' for help. Type 'exit' to quit.

>> model Product product

first Time I try this command :

C:\Program Files\EasyPhp2.0b1\www\YiiRoot\framework\WebRoot\testdrive\Proteced>yiic shell yiic.bat

Then I try this command:

C:\Program Files\EasyPhp2.0b1\www\YiiRoot\framework>yiic shell WebRoot/testdrive/index.php

Then i get following error in command prompt:

<!DOCTYPE html

PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">             

<html xmlns="" xml:lang="en" lang="en">             <head>                                                                         

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>            <title>                                                                         

PHP Error</title>                                                                                                                                               <style type="text/css">


body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}   

h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }        h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }   

 h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}                     

p {font-family:"Verdana";font-size:9pt;}                                       

pre {font-family:"Lucida Console";font-size:10pt;}                              .version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}              .message {color: maroon;}                                                     

 .source {font-family:"Lucida Console";font-weight:normal;background-color:#ffffee;}                                                                           

 .error {background-color: #ffeeee;}                                             /*]]>*/                                                                         </style>                                                                        </head>                                                                                                                                                         <body>                                                                         

<h1>PHP Error</h1>                                                                                                                                              <h3>Description</h3>                                                           

 <p class="message">

Illegal offset type in isset or empty</p>                                                                                                                       <h3>Source File</h3>

 <p> C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkYiiBase.php(175)</p>                                                                                       <div class="source">

<pre>00163:      * the class file &#039;web/CController.php&#039; when needed.       00164:      *                 

 00165:      * The same alias can be imported multiple times, but only the first time is effective.   

                00166:      *          00167:      * @param string path alias to be imported         00168:      * @param boolean whether to include the class file immediately. If false, the class file                 00169:      * will be included only when the class is being used.               00170:      * @return string the class name or the directory that this alias refers to                              00171:      * @throws CException if the alias is invalid                        00172:      */                                                               

  00173:     public static function import($alias,$forceInclude=false)            00174:     


 <div class="error">00175:       

 if(isset(self::$_imports[$alias]))  // previously imported                                                                    </div>00176:             

return self::$_imports[$alias];                        00177:                                                                       

   00178:         if(isset(self::$_coreClasses[$alias]) || ($pos=strrpos($alias,&#039;.&#039;))===false)  // a simple class name                                   00179:         {                                                               

00180:             self::$_imports[$alias]=$alias;                              00181:             if($forceInclude &amp;&amp; !class_exists($alias,false))     00182:             {                                                            00183:                 if(isset(self::$_coreClasses[$alias])) // a core class   00184:                     require_once(YII_PATH.self::$_coreClasses[$alias]);  00185:                 else                                                     00186:                     require_once($alias.&#039;.php&#039;);               00187:             }                                                            </pre>                          </div><!-- end of source -->                                                                                                                                    <h3>Stack Trace</h3>                                                           

<div class="callstack">                                                         <pre>                                                                           

#0 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkcollectionsCConfiguration.php(131): import()   

 #1 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkbaseCApplication.php(709): createObject()                                                           

  #2 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkbaseCApplication.php(361): CWebApplication-&gt;getComponent()                                         

 #3 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkclicommandsshellModelCommand.php(92): CWebApplication-&gt;getDb()                                   

 #4 unknown(0): ModelCommand-&gt;generateModel()   

#5 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkconsoleCConsoleCommand.php(116): call_user_func()                                                     

 #6 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkclicommandsshellModelCommand.php(72): ModelCommand-&gt;copyFiles()                                   

#7 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkclicommandsShellCommand.php(98): ModelCommand-&gt;run()                                               

#8 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkclicommandsShellCommand.php(78): ShellCommand-&gt;runShell()                                         

#9 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkconsoleCConsoleCommandRunner.php(62): ShellCommand-&gt;run()                                         

#10 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkconsoleCConsoleApplication.php(88): CConsoleCommandRunner-&gt;run()                                 

 #11 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkbaseCApplication.php(146): CConsoleApplication-&gt;processRequest()                                   

#12 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkyiic.php(30): CConsoleApplication-&gt;run()                                                         

  #13 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkyiic(15): require_once() </pre></div>

<!-- end of callstack-->

<div class="version"> 2009-01-05 05:47:35 <a href="">Yii Framework</a>/1.0.0</div>  </body>                                                                         </html>                                                                       


I trying this in Windows with Mysql.

Please Help me Thanks in advance.

I am confused. You should only use "yiic shell path/to/index.php" to start yiic shell.


I'm getting this error as well about offset types being illegal or empty. After creating my webapp i run:

yiic shell c:/xampp/htdocs/

model User

And i get that error response:

Illegal offset type in isset or empty

I'm not too sure why it's like this. I do suspect it is database related because i tried switching to another database and it works.

Attached my database schema (MySQL). Could anyone take a look?


I changed line 225 on ModelCommand.php (generateRelationName) to:



and it works now. What are the implications? From what I see that it should be fine.

hmm…this is strange. The while loop is there to obtain a relation name that is not a column name. Are you able to check what is $relationName that causes the problem?

Well when i changed the line it did still have the error message but created the models successfully as well.

Some of the relation names were generated wrongly though so i had to manually modify them:

  • rated_item

  • reviewed_item

And similar.

Could you try to import the MySQL schema i attached on a previous post and run the shell model creation commands, and see if you can replicate the error? I have no idea which relation names are causing the problems.

Thanks. I just fixed this bug. It is because one of your FKs is named as 'id'.


Thanks for fixing the bug, although it was really not my intention on that foreign key that was "id", it should have been "vendor". Darn.