realtebo
realtebo

Reputation: 25691

Yii 1: Could not find driver error when connecting to microsoft sql server

I successfully tested that my PHP can connect to my MS SQL SERVER.

<?php

$server = 'SRV-MEXAL';

// Connect to MSSQL
$link = mssql_connect($server, 'mexal_db_usr', 'password_changed');

if (!$link) {
    die('Something went wrong while connecting to MSSQL');
} else {
    echo "Works <br>";
    $OK = mssql_select_db ("at6_rp");

    echo $OK ? "ok" : "ko";

}
?>

Using this script I got both Works and ok, so connection and db selection are both working.

I tried to configure my db connection into Yii 1 main.php

"mexal_db" => array (
        'class'                 => "CDbConnection",
        'connectionString'      => 'sqlsrv:Server=SRV-MEXAL; Database=at6_rp',
        'enableParamLogging'    => false,
        'username'              => 'mexal_db_usr',
        'password'              => 'password_changed',
        'charset'               => 'utf8',
    ),

But when trying to instantiate it, I got this exception

CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /var/www/httpdocs/test1.phonix.it/yii/framework/db/CDbConnection.php:399

What am I doing wrong?

Upvotes: 0

Views: 3099

Answers (1)

Nana Partykar
Nana Partykar

Reputation: 10548

You will have php.ini inside your project folder. (In yii2, i am having inside web folder. In yii1, I don't know where php.ini file is located.) So, please find your php.ini file of your project folder.

Inside php.ini, search for pdo_mssql.so.

;extension=pdo.so
;extension=pdo_mssql.so

Remove ; from it. Like

;extension=pdo.so
extension=pdo_mssql.so

Restart your server. It will work.

For more info, check this could not find driver - Yii

Upvotes: 1

Related Questions