How do I connect to a SQL Server database in CodeIgniter?
I\'m currently starting an application in CodeIgniter and I would like to use SQL Server.
$
I just got this problem solved. And I was connecting to MSSQL hosted with microsoft Azure
Steps I followed after several research work on internet are as follows :
database.cfg :
$db['default']['hostname'] = 'XXXXXXX.database.windows.net';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'databasename';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;
Mainly dbdriver,pcconnect and the hostname you should configure properly. Rest are common. Get hostname from your azure database details.
And I also modified couple of system files as I heard there were issues with DB driver.
system/database/drivers/sqlsrv/sqlsrv_driver.php
function db_pconnect()
{
//$this->db_connect(TRUE);
return $this->db_connect(TRUE);
}
and
function affected_rows()
{
//return @sqlrv_rows_affected($this->conn_id);
return @sqlsrv_num_rows($this->result_id);
}
I was able to connect to database and create database application.
Hope it will help someone in need :)