使用odbc将Codeigniter 3与MS SQL Server连接

时间:2017-02-23 07:23:26

标签: php codeigniter

我有一个CI项目,需要连接到远程SQL Server 2000数据库,我正在使用ODBC驱动程序。我一直收到数据库错误:

遇到PHP错误

  

严重性:警告

     

消息:odbc_pconnect():SQL错误:[Microsoft] [ODBC驱动程序管理器]   未找到数据源名称且未指定默认驱动程序,SQL状态   SQLConnect中的IM002

     

文件名:odbc / odbc_driver.php

     

行号:140

     

回溯:

     

文件:C:\ wamp \ www \ xxx \ application \ controllers \ Welcome.php行:30   功能:__construct

     

文件:C:\ wamp \ www \ xxx \ index.php行:315功能:require_once

这是我的数据库配置

$db['default'] = array(
    'dsn'   => 'MyServerName',
    'hostname' => 'Driver={SQL Server Native Client 10.0};Server=ServerIPAddress;Database=MyDB;',
    'username' => 'sa',
    'password' => 'sa',
    'database' => '*MyDB*',
    'dbdriver' => 'odbc',
    'dbprefix' => '',
    'pconnect' => TRUE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

1 个答案:

答案 0 :(得分:0)

嗨,我知道这太晚了,因为我刚刚在 SO 中恢复了我的帐户详细信息,所以我通过在 database.php 文件中使用它作为主机名解决了这个问题

'hostname' => 'Driver={SQL Server};Server=<*Server IP Address*>;Database=<*Database Name>*;',