简体   繁体   中英

Codeigniter - SQLServer Database Connection Error

Got a question and problem to share. So I tried to connect Codeigniter 3.0.5 to SQL Server. However I always get this error no matter what I tried.

    A Database Error Occurred
    Unable to connect to your database server using the provided settings.
    Filename: core/CodeIgniter.php
    Line Number: 500

My Settings are

    $active_group = 'default';
    $query_builder = TRUE;

    $db['default'] = array(
        'dsn'   => '',
        'hostname' => 'MYSQLSERVERHOSTNAME',
        'username' => '',//Empty I dont use any (Windows Auth)
        'password' => '',//Dont use any
        'database' => 'MYSQLSERVERDATABASENAME',
        'dbdriver' => 'sqlsrv',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    );

I have set TCP/IP enabled and added 1433 port on IPAll. Restarted the services few times and still got this error. However my other friend's computer can connect to the database with this settings. I'm using PHP 5.6 and SQLSRV32 as extension. Does anyone know why? and how can I check error log for CI connection to database?

PS : I tried copying my friends CI (the one that runs) in case I miss something when code it and deleted some line then I change the host name and it still didn't work. So something is probably wrong with my SQL installation maybe, so I tried to check the installation in control panel... but there no different since we are using from the same installation. Getting really confuse here...

Much Thanks!

Hey after browsing a bit I founded the problem of why I can't connect to sqlsrv. I have been missing odbc 11 driver. I knew that after I code this line on config/database.php

$link = sqlsrv_connect('SQLSERVERHOSTNAME');

if (!$link) {
     print_r(sqlsrv_errors());
     die();
}

So yeah somehow I don't know why I have to install this driver first because when I ask my friend, he didn't remember installing odbc driver 11 manually . So yeah, if you are one of the few to have this weird problem, try to check the log. Thanks for any help by the way hehe :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM