CDbConnection failed to open the DB connection: could not find driver

CDbConnection failed to open the DB connection: could not find driver

C:\AppServ\www\yii\framework\db\CDbConnection.php(364)

352 throw new CDbException(Yii::t(‘yii’,‘CDbConnection.connectionString cannot be empty.’));

353 try

354 {

355 Yii::trace(‘Opening DB connection’,‘system.db.CDbConnection’);

356 $this->_pdo=$this->createPdoInstance();

357 $this->initConnection($this->_pdo);

358 $this->_active=true;

359 }

360 catch(PDOException $e)

361 {

362 if(YII_DEBUG)

363 {

364 throw new CDbException(Yii::t(‘yii’,‘CDbConnection failed to open the DB connection: {error}’,

365 array(’{error}’=>$e->getMessage())),(int)$e->getCode(),$e->errorInfo);

366 }

367 else

368 {

369 Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,‘exception.CDbException’);

370 throw new CDbException(Yii::t(‘yii’,‘CDbConnection failed to open the DB connection.’),(int)$e->getCode(),$e->errorInfo);

371 }

372 }

373 }

374 }

375

376 /**

test it:

‘connectionString’ => ‘mysql: host = localhost; dbname = database’,

change to

‘connectionString’ => ‘mysql: host = 127.0.0.1; dbname = database’,




/*a MySQL database*/

		

		'db'=>array(

			'connectionString' => 'mysql:host=127.0.0.1;dbname=data_site',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '102030',

			'charset' => 'utf8',

		),



other…

checks enabled PDO in php

extension = php_pdo.dll

extension = php_pdo_mysql.dll

I had this same issue and have been pulling my hair out. Finally worked it out. I am using WAMP for development on my local machine. I also had PHP installed separately. It turns out the apache server in WAMP was using the php.ini from the PHP install rather than the php.ini in WAMP so no PDO drivers were loaded. I updated the apache httpd.conf file with the following to point it at the correct php.ini

PHPIniDir "C:\wamp\bin\php\php5.3.13"

phpinfo() should show you the path to your php.ini file and any PDO drivers active.

Hope this helps someone!

If Yo’re using Sqlite and GNU/Linux debian based: As root (or use sudo) apt-get install php5-sqlite to solve this problem. :lol: