我正在尝试学习Yii,但我被一个非常持久的错误所困扰,每当我使用Yii时,这个错误就会上升。第一个系统细节:带有apache2的Ubuntu13.04,php 5.5.3和mysql 5.5.3。我运行/yiic migrate
在我正在开发的webapp应用程序的/protected中。
我得到了错误:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /var/www/yii/framework/db/CDbConnection.php:382这似乎是因为在CDbConnection.php的第382行,脚本检查是否安装了pod_mysql,但找不到它。
`if($this->_pdo===null)
{
if(empty($this->connectionString))
throw new CDbException('CDbConnection.connectionString cannot be empty.');
try
{
Yii::trace('Opening DB connection','system.db.CDbConnection');
$this->_pdo=$this->createPdoInstance();
$this->initConnection($this->_pdo);
$this->_active=true;
}
catch(PDOException $e)
{
if(YII_DEBUG)
{
throw new CDbException('CDbConnection failed to open the DB connection:'.
$e->getMessage(),(int)$e->getCode(),$e->errorInfo);
}
else
{
Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,'exception.CDbException');
throw new CDbException('CDbConnection failed to open the DB connection.'
,(int)$e->getCode(),$e->errorInfo);
}
}
}^^这里是相关的代码片段。
运行的结果
php -i|grep PDO gives
PDO
PDO support => enabled
PDO drivers => sqlite
PDO Driver for SQLite 3.x => enabled所以我的问题似乎是只有sqlite驱动程序在运行。但是,我已经确保检查是否安装了php-mysql (因为pdo_mysql已被弃用,并且在此包中)。我已经没有办法了,我将感谢所有人的帮助!!
提前感谢!
发布于 2013-12-20 07:20:29
控制台应用程序有自己的配置存储在protected/config/console.php中。请确保您已在其中配置了数据库组件。
发布于 2015-01-01 15:21:29
此问题来自您的phpcli.ini,而不是php.ini。在您的phpcli.ini中,您应该添加:
extension=php_pdo_mysql.dll与php.ini中的一样
https://stackoverflow.com/questions/20692528
复制相似问题