Can't connect to database

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(


	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


	'name'=>'My Web Application',





	// autoloading model and component classes


	'import'=>array(


		'application.models.*',


		'application.components.*',


		'system.web.*',


		'system.db.*',


	),





	// application components


	'components'=>array(


		'user'=>array(


			// enable cookie-based authentication


			'allowAutoLogin'=>true,


		),


		// uncomment the following to set up database





		'db'=>array(


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


                        'username'=>'root',


                        'password'=>'',





		),





	),


);


Please help me .

Thanks in advance.

The error is complaining that Yii::app() is null.

What is your entry script? How did you call this model command?

Hi, Thanks for replying.

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

the code of index.php of testdrive is as follow:

<?php





// change the following paths if necessary


$yii='C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkyii.php';


$config=dirname(__FILE__).'/protected/config/main.php';





// remove the following line when in production mode


defined('YII_DEBUG') or define('YII_DEBUG',true);





require_once($yii);


Yii::createWebApplication($config)->run();


?>

Please Help me.

When I try to run command with different entry point like this

yiic shell WebRoot/testdrive/index.php

Then I get This error on command line:



<!DOCTYPE html 


PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">             


<html xmlns="http://www.w3.org/1999/xhtml" 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"> 


/*<![CDATA[*/                                                                   


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="http://www.yiiframework.com/">Yii Framework</a>/1.0.0</div>  </body>                                                                         </html>