Codeigniter未连接到SQL Server

时间:2013-07-25 08:47:51

标签: php sql-server codeigniter-2

我正在尝试使用CodeIgniter连接到SQL服务器。如果我使用sqlsrv驱动程序 - 我收到一个致命的错误消息,如果我使用odbc驱动程序 - 我得到一个'无法使用提供的设置错误消息连接到您的数据库服务器。有谁知道如何解决这个问题???我不介意如何,我只想让Codeigniter连接到SQL Server数据库。

这是数据库配置文件

$db['otherdb']['hostname'] = '195.234.10.55\SQLEXPRESS';
$db['otherdb']['username'] = 'username';
$db['otherdb']['password'] = 'password';
$db['otherdb']['database'] = 'ONEDB';
$db['otherdb']['dbdriver'] = 'odbc'; // Done this in both ODBC and SQLSRV
$db['otherdb']['dbprefix'] = '';
$db['otherdb']['pconnect'] = TRUE;
$db['otherdb']['db_debug'] = TRUE;
$db['otherdb']['cache_on'] = FALSE;
$db['otherdb']['cachedir'] = '';
$db['otherdb']['char_set'] = 'utf8';
$db['otherdb']['dbcollat'] = 'utf8_general_ci';
$db['otherdb']['swap_pre'] = '';
$db['otherdb']['autoinit'] = TRUE;
$db['otherdb']['stricton'] = FALSE;

由于

1 个答案:

答案 0 :(得分:0)

(不要意味着复活一篇旧帖子,但以防其他人正在寻找答案,因为这篇文章是在我的搜索过程中出现的......)

使用本机驱动程序从CodeIgniter 3连接到SQL_server的简短分步指南:

  1. 首先从this下载PHP for SQL_server Microsoft本机驱动程序。注意选择适合您设置的那个。
  2. 将其安装到PHP扩展目录。

  3. 在PHP.ini中配置新扩展。取消注释或附加行(取决于选择的驱动程序版本)。即:

    extension = php_sqlsrv_55_ts.dll
    
  4. 重启Apache。

    现在您的PHP设置可以连接到SQL_server数据库。

  5. 通过配置application / config / database.php来设置CodeIgniter数据库连接

    <?php
    
        // native-driver connection
        $db['default'] = array(
            'dsn'    => '',
            'hostname' => 'SERVER\SQLEXPRESS',
            'username' => 'test_user',
            'password' => 'test_password',
            'database' => 'test01',
            'dbdriver' => 'sqlsrv',
            'dbprefix' => '',
            'pconnect' => FALSE,
            'db_debug' => TRUE,
            'cache_on' => FALSE,
            'cachedir' => 'application/cache',
            'char_set' => 'utf8',
            'dbcollat' => 'utf8_general_ci',
            'swap_pre' => '',
            'autoinit' => TRUE,
            'encrypt' => FALSE,
            'compress' => FALSE,
            'stricton' => FALSE,
            'failover' => array(),
        'save_queries' => TRUE
        );
    
  6. 在SQL_server 2008 R2和SQL_server 2014 express上从CodeIgniter 3.0.1测试。