April 2, 2012

How to connect the 'MSSQL' database in Codeigniter Framework?

Question by Bhavin Rana

How to connect the ‘MSSQL’ database in Codeigniter Framework ?

i m currectly starting an application which is on codeignitor framework and for db i would like to use the mssql.

applicationconfigdatabase.php file settings here.

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = '#.#.#.27';
$db['default']['username'] = '@@@@@@';
$db['default']['password'] = '@@@@@@@@@';
$db['default']['database'] = '$$$$$$$$$$$$$';
$db['default']['dbdriver'] = 'mssql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

after changing the ‘libraries’ in to autoload.php in config folder
it shows just a black white page only with no any of errors.
can you please tell me what other changes i have to do to work with the MSSQL Database ?

#autoload.php#

$autoload['libraries'] = array('database');

Many Thanks in Advance !
😀

Answer by Starx

Your Configuration code is fine. Further reading here

IF you believe the errors are not showing up, then go to the index.php and on the top place the following snippet to show the errors.

error_reporting(E_ALL);

Other, then this check if the MSSQL service is running and is accessible. May be create a simple .php and try a connection with plain codes.

A non CI file Something like,

<?php
$server = 'YOURPCSQLEXPRESS';
$link = mssql_connect($server, 'user', 'pass');

if (!$link) {
    die('Something went wrong while connecting to MSSQL');
}
?>
...

Please fill the form - I will response as fast as I can!