Search code examples
phpmysqlyiizend-studioyii-cactiverecord

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


while trying to connect with mysql in yii framework it shows

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

php code :

     'db'=>array(
        'class' => 'CDbConnection',
        'connectionString' => 'mysql:host=localhost:3306;dbname=testdrive',
        'emulatePrepare' => true,
        'username' => 'root',
        'password' => 'root',
        'charset' => 'utf8',
    ), 

my php drivers are already enabled , but it shows the same error

Im using zend studio, zend server for this

how could i fix this?


Solution

  • Things you should check

    First you should check phpinfo() for the pdo_drivers installed.

    if u use IIS server , you should check php extensions installed or not.

    check php.ini for extensions_dir is properly given

    check you ext folder in php contains pdo_mysql dlls

    Some times the problem may occur due to zend server installation .You should check zend server is properly using the php extensions

    After that check simple php-mysql connection using the following functions

    mysql_connect('localhost:3306','root','root');
    mysql_select_db('testdrive');
    

    If it works then go with Yii, Slim, Zend php-mysql connections