2014-07-16 225 views
3

我是PHP和Yii PHP框架的新手。Yii遷移問題

我想在本地機器上運行一個應用程序。我首先需要遷移數據庫。對於這我運行下面的命令,

protected/yiic migrate 

但它拋出CDbException與以下堆棧跟蹤...

Yii Migration Tool v1.0 (based on Yii v1.1.14) 

exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /var/www/Prepaid-Card/web/framework/db/CDbConnection.php:382 
Stack trace: 
#0 /var/www/Prepaid-Card/web/framework/db/CDbConnection.php(330): CDbConnection->open() 
#1 /var/www/Prepaid-Card/web/framework/db/CDbConnection.php(308): CDbConnection->setActive(true) 
#2 /var/www/Prepaid-Card/web/framework/base/CModule.php(387): CDbConnection->init() 
#3 /var/www/Prepaid-Card/web/framework/cli/commands/MigrateCommand.php(442): CModule->getComponent('db') 
#4 /var/www/Prepaid-Card/web/framework/cli/commands/MigrateCommand.php(451): MigrateCommand->getDbConnection() 
#5 /var/www/Prepaid-Card/web/framework/cli/commands/MigrateCommand.php(482): MigrateCommand->getMigrationHistory(-1) 
#6 /var/www/Prepaid-Card/web/framework/cli/commands/MigrateCommand.php(84): MigrateCommand->getNewMigrations() 
#7 [internal function]: MigrateCommand->actionUp(Array) 
#8 /var/www/Prepaid-Card/web/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(MigrateCommand), Array) 
#9 /var/www/Prepaid-Card/web/framework/console/CConsoleCommandRunner.php(71): CConsoleCommand->run(Array) 
#10 /var/www/Prepaid-Card/web/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run(Array) 
#11 /var/www/Prepaid-Card/web/framework/base/CApplication.php(180): CConsoleApplication->processRequest() 
#12 /var/www/Prepaid-Card/web/framework/yiic.php(33): CApplication->run() 
#13 /var/www/Prepaid-Card/web/protected/yiic.php(7): require_once('/var/www/Prepai...') 
#14 /var/www/Prepaid-Card/web/protected/yiic(4): require_once('/var/www/Prepai...') 

這裏是我的console.php文件

<?php 

return array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..', 
    'name' => 'Prepaid Card', 
    // preloading 'log' component 
    'preload' => array('log'), 
    'import' => array(
     'application.models.*', 
     'application.components.*', 
     'application.extensions.*', 
     'ext.YiiMailer.YiiMailer' 
    ), 
    // application components 
    'components' => array(
     'db' => require(dirname(__FILE__) . '/../../../../DbConfig.php'), 
     'log' => array(
      'class' => 'CLogRouter', 
      'routes' => array(
       array(
        'class' => 'CFileLogRoute', 
        'levels' => 'error, warning', 
       ), 
      ), 
     ), 
    ) 
); 

我已經安裝的MySQL並創建了後續的數據庫。我的DbConfig文件看起來像

<?php 
return array(
    'connectionString' => 'mysql:host=localhost;dbname=db_ppc', 
    'emulatePrepare' => true, 
    'username' => 'root', 
    'password' => 'helloworld', 
    'charset' => 'utf8', 
); 

我只是想不通這裏的問題。

我在做什麼錯在這裏?這個問題的原因是什麼?請幫我解決它。

謝謝!

+0

這是數據庫連接錯誤檢查你的mysql連接 –

+2

你在你的系統中安裝了PDO嗎? – JorgeeFG

+0

是的,但@ramamoorthy_villi我有一個正確的連接證書的MySQL ...這就是問題所在?我無法弄清楚我做錯了什麼? – Runcorn

回答

1

「CDbConnection無法打開數據庫連接:無法找到驅動程序」。這個消息告訴你在你的環境中配置的東西不好。檢查您的PHP配置數據庫驅動程序,並重新啓動/重新加載您的Apache加載新的配置。