dopa53272 2016-02-02 11:27
浏览 78
已采纳

Yii 1:连接到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?

  • 写回答

1条回答 默认 最新

  • drex88669 2016-02-02 11:45
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝