Cdbconnection Failed

Hi,

I have a weird problem with existing Yii application.

Recently I installed Linux Mint and set up apache, php, and mysql with no problems.

Phpmyadmin and ‘normal’ applications work without problems but my Yii application throws “CDbConnection failed to open the DB connection: could not find driver”.

So i thought maybe PDO driver is missing but it’s not. Phpinfo says PDO driver is loaded and I connected to database with


new PDO('mysql:host=localhost;dbname=$mydb', $user, $pass);

with no problems.

Also,


print_r(PDO::getAvailableDrivers());

shows


Array ( [0] => mysql )

In application connection is set with:


'components'=>array(

            'db'=>array(

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

                'emulatePrepare' => true,

                'username' => 'root',

                'password' => '',

                'charset' => 'utf8',

                'enableParamLogging'=> true,

                'schemaCachingDuration' => 3600,

                'class'=>'CDbConnection',

            ),

        ),

and it worked so far in windows with no problems.

I out of ideas why this wouldn’t work. Any help is appreciated.

Maybe you should write ‘localhost’ instead of ‘127.0.0.1’.

Or try to use PDO in your yii-aplication.

There are two drivers for MySQL in Ubuntu, mysql and mysqli. Try using the second one in the connection string.

Tried localhost, no joy. Tried with manual connection to PDO (example below), it works.




try {

    $dbh = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');

    foreach($dbh->query('SELECT * from polls') as $row) {

        print_r($row);

    }

    $dbh = null;

} catch (PDOException $e) {

    print "Error!: " . $e->getMessage() . "<br/>";

    die();

}

If you mean like writing


'connectionString' => 'mysqli:host=127.0.0.1;

i tried but then even the above conneciton string throws "could not find driver".

I will try to dig through error stack trace to find what’s different in yii connection from the one above.

Try shorted code.

Tried it, didn’t work. What I did in the end is reinstall whole LAMP, redownloaded Yii and now it works. So I don’t know what the problem was but at least it works.

Thanks for your time anyway.

please, remember say <SOLVED> ;)