How do I connect to a SQL Server database in CodeIgniter?
Solution 1
use use $db['default']['dbdriver'] = 'sqlsrv';
and install Microsoft Drivers for PHP for SQL Server on windows
Solution 2
I couldn't get it to work with the supported driver of mssql
so I used sqlsrv
I normally connect with ip,port as the hostname
, so I changed that.
pconnect
was also giving me issues. I set it to FALSE
and it started working.
Here is the configuration I got to work:
$db['default']['hostname'] = '127.0.0.1,1433';
$db['default']['username'] = 'username1';
$db['default']['password'] = 'secretpassword';
$db['default']['database'] = 'databasename';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Bhavin Rana
I, Bhavin Rana, Proffesional Web Developer | Software Programmer. having deep knowledge of various programming languages, here i m sharing knowledge via Stack. Areas of my interests are : JQuery, Codeignitor, Wordpress, Jhoomla, CakePHP, CustomPHP, WebDesign, WebHosting & All Web-Developments Email: [email protected] www.bhavinrana.com
Updated on March 02, 2020Comments
-
Bhavin Rana about 4 years
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.
$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 auto-loading the database, it shows just a blank white page with no errors. Can you please tell me what other changes I have to make to work with the SQL Server database?
#autoload.php# $autoload['libraries'] = array('database');