Connect CodeIgniter to SQL Server using sqlsrv driver

1.       Wamp Server 2.0 with PHP 5.2
2.       CodeIgniter 2.1/2.2
3.       SQL Server 2005/2008
Download First
1.       Download sqlsrv dll driver SQLsrv20.exe (download here)
2.       Download SQL Native Client 2008 (Native Client 10) which is compatible for SQL Server 2005/2008 (download here)
How to connect CodeIgniter to SQL Server 2005 using SQLsrv driver
1.       Install / Upgrade your SQL Native Client to 2008 SP3 (Native Client 10), then restart your computer
2.       Stop your Wamp Server to copy dll file
3.       Install or extract  sqlsrv dll files , you don’t have to copy all of the files , choose the files that have same version with your installed PHP version, in this case I will copy
php _sqlsrv_52_ts_vc6.dll

Then I’ll copy the files into  :
4.       Next , I will edit php.ini , the location of the file is in ..wampbinapacheapache2.2.8binand adding these lines in extension configuration section :
5.       Start the wamp service
6.       Create test.php(not codeigniter file) the file will be used to test the connection (it’s common native PHP Script )
Adjust with your own host/database/user/password setting in SQL Server
$serverName = “SISINDOTEKPRIMAVERA”; //serverNameinstanceName
$connectionInfo = array( “Database”=>”cisqldb”, “UID”=>”sa”, “PWD”=>”sa”);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
     echo “Connection established.<br />”;
     echo “Connection could not be established.<br />”;
     die( print_r( sqlsrv_errors(), true));
7.  If the Connection established.  You may try to setup your codeigniter database configuration file (database.php) in 
8.       Change the configuration such as mention bellowed (Use your own configuration !)
9.       Don’t forget to change the value of  $db[‘default’][‘pconnect’] = FALSE;
$active_group = ‘default’;
$active_record = TRUE;
$db[‘default’][‘hostname’] = ‘SISINDOTEKPRIMAVERA’;
$db[‘default’][‘username’] = ‘sa’;
$db[‘default’][‘password’] = ‘sa’;
$db[‘default’][‘database’] = ‘cisqldb’;
$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;
Save the file and now you may try to run your codeigniter web that connected to SQL Server by using sqlsrv dll driver
I Hope that can help you guys !, (
By :
Freelance Inhouse Trainer

Hery Purnama – 081.223344.506 –
Freelance IT Trainer, Trainer Excel VBA Macro, Trainer Sencha ExtJS, Trainer Google Map API, Trainer SPSS, Trainer MS Project, Trainer Primavera, Trainer Google Sktechup 3D, Trainer Android Phonegap, Trainer Oracle, Trainer SQL Server, Trainer MySQL, Trainer PHP Jquery Mobile , Trainer Java, Trainer HTML5 Javascript, Trainer SEO Internet Marketing, Trainer Project Management, Trainer SMS Gateway, Trainer CMS WordPress, ITIL, COBIT

Author: Inhouse Trainer freelance

Hery Purnama 081.223344.506 - Freelance Trainer , Excel VBA Macro, Android, Phonegap, ITIL, COBIT, Google Map API, Sketchup3D , MS Project, Sencha ExtJS, Oracle , MySQL DBA, MS. Access VBA, Primavera P6, MS Project ,Jquery, Yii, CodeIgniter. laravel, CATIA 3D, Unity 5 , PMBOK, PMO, TOGAF, PRINCE2 - Call : 081.223344.506 | PinBB : 7DC633AA| Email / YM : | FB : inhousetrainer | TW : inhousetrainer

Leave a Reply

Your email address will not be published. Required fields are marked *