Yii迁移问题

时间:2014-07-16 03:50:08

标签: php mysql yii

我是PHP和Yii PHP Framework的新手。

我正在尝试在本地计算机上运行应用程序。我首先需要迁移数据库。为此我运行以下命令,

protected/yiic migrate

但它会抛出CDbException以下的Stack Trace ...

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',
);

我无法在这里找出问题。

我在这里做错了什么?这个问题可能是什么原因?请帮我解决一下。

感谢!!!

1 个答案:

答案 0 :(得分:1)

“CDbConnection无法打开数据库连接:无法找到驱动程序”。此消息告诉您在您的环境中配置的内容不是很好。检查您的php配置是否有数据库驱动程序,然后重新启动/重新加载您的apache以加载新配置。