没有连接到SQL Server的Codeigniter。

时间:2022-01-07 01:43:56

I'm trying to connect to an SQL server using CodeIgniter. If I use the sqlsrv driver - I get a fatal error message and if I use the odbc driver - I get an 'Unable to connect to your database server using the provided settings error message. Does anyone know how to fix this problem??? I don't mind how, I just want Codeigniter to connect to the SQL Server Database.

我尝试使用CodeIgniter连接到一个SQL服务器。如果我使用sqlsrv驱动程序——我得到一个致命错误消息,如果我使用odbc驱动程序——我将无法使用所提供的设置错误消息连接到您的数据库服务器。有人知道怎么解决这个问题吗?我不介意,我只是想要Codeigniter连接到SQL Server数据库。

This is the database config file

这是数据库配置文件。

$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;

Thanks

谢谢

1 个解决方案

#1


0  

(Don't mean to resurrect an old post, but just in case others are looking for the answer, and because this post came up during my search...)

(不要想让旧的帖子复活,只是以防其他人在寻找答案,因为这篇帖子是在我搜索的时候出现的…)

A short step-by-step guide to connect to SQL_server from CodeIgniter 3 using native driver:

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

  1. First of all download PHP for SQL_server Microsoft native driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098. Take care to choose the one that fits your setup.
  2. 首先,从http://www.microsoft.com/en-us/download/details.aspx?id=20098下载SQL_server Microsoft本地驱动程序的PHP。小心选择适合你的设置。
  3. Install it to the PHP extension directory.

    将其安装到PHP扩展目录。

  4. Configure the new extension in PHP.ini. uncommenting or appending the line (depending on the choosen driver version). I.e.:

    配置PHP.ini中的新扩展。取消注释或附加行(取决于choosen驱动程序版本)。例如:

    extension = php_sqlsrv_55_ts.dll
    
  5. Restart Apache.

    重新启动Apache。

    Now your PHP setup is able to connect to SQL_server databases.

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

  6. Set up your CodeIgniter database connection by configuring application/config/database.php like

    通过配置应用程序/配置/数据库设置CodeIgniter数据库连接。php之类的

    <?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
        );
    

Tested from CodeIgniter 3.0.1 on SQL_server 2008 R2 and SQL_server 2014 express.

在SQL_server 2008 R2和SQL_server 2014 express上测试了CodeIgniter 3.0.1。

#1


0  

(Don't mean to resurrect an old post, but just in case others are looking for the answer, and because this post came up during my search...)

(不要想让旧的帖子复活,只是以防其他人在寻找答案,因为这篇帖子是在我搜索的时候出现的…)

A short step-by-step guide to connect to SQL_server from CodeIgniter 3 using native driver:

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

  1. First of all download PHP for SQL_server Microsoft native driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098. Take care to choose the one that fits your setup.
  2. 首先,从http://www.microsoft.com/en-us/download/details.aspx?id=20098下载SQL_server Microsoft本地驱动程序的PHP。小心选择适合你的设置。
  3. Install it to the PHP extension directory.

    将其安装到PHP扩展目录。

  4. Configure the new extension in PHP.ini. uncommenting or appending the line (depending on the choosen driver version). I.e.:

    配置PHP.ini中的新扩展。取消注释或附加行(取决于choosen驱动程序版本)。例如:

    extension = php_sqlsrv_55_ts.dll
    
  5. Restart Apache.

    重新启动Apache。

    Now your PHP setup is able to connect to SQL_server databases.

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

  6. Set up your CodeIgniter database connection by configuring application/config/database.php like

    通过配置应用程序/配置/数据库设置CodeIgniter数据库连接。php之类的

    <?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
        );
    

Tested from CodeIgniter 3.0.1 on SQL_server 2008 R2 and SQL_server 2014 express.

在SQL_server 2008 R2和SQL_server 2014 express上测试了CodeIgniter 3.0.1。