How to connect Codeigniter with MSSQL (SQL Server)?
it will be helpful for someone
Detail steps for How to connect SQL Server with PHP in WampServer
step 1)
download the appropriate driver based on your php version, check using php_info() function, for me 5.6, so the appropriate driver is SQLSRV30, found in the following linkhttps://www.microsoft.com/en-us/download/details.aspx?id=20098
step 2) extract the drives in C:\wamp\bin\php\php5.6.19\extfocus on the following .dll file they should be there, otherwise we can't connect with SQL, these are
php_sqlsrv_56_nts.dll and php_sqlsrv_56_ts.dll
step 3) enable the drives in php.ini as follow, which is found in C:\wamp\bin\apache\apache2.4.18\bin as follow
extension=php_sqlsrv_56_ts.dll extension=php_sqlsrv_56_nts.dll
step 4) go to DB_driver.php line 96found inC:\wamp\www\public\system\database\DB_driver.phpplease replace the mysqli by sqlsrv
public $dbdriver = ' mysqli '; public $dbdriver = 'sqlsrv';
step 5) last and most important part, go to CI database configin database.php file which's found in C:\wamp\www\public\application\config\database.phpadjust the params accordingly...
$db['default'] = array(
'dsn' => '','hostname' => 'ip address for sql server,port', // it should be SQL TCP enabled and firewall permitted for SQL port, whether default or custom.'username' => 'your user name here','password' => 'your pwd here','database' => 'your db here','dbdriver' => 'sqlsrv','dbprefix' => '','pconnect' => TRUE,'db_debug' => (ENVIRONMENT !== 'production'),'cache_on' => FALSE,'cachedir' => '','char_set' => 'utf8','dbcollat' => 'utf8_general_ci','swap_pre' => '','encrypt' => FALSE,'autoinit' => TRUE,'compress' => FALSE,'stricton' => FALSE,'failover' => array(),'save_queries' => TRUE
);
happy coding...
You may want to try odbc driver (built-in db driver in PHP). Mssql driver doesn't come convenient in PHP.
I got this working with CI 2.2.0 connected to MSSQL 2014 database (all Windows platform). I've also tried this using MSSQL 2012 before.
$active_group = 'my_mssql';$active_record = TRUE;$db['my_mssql']['hostname'] = 'Driver={SQL Server Native Client 11.0};Server=Host\Instance;Database=queue_sys;';$db['my_mssql']['username'] = 'wow_queue';$db['my_mssql']['password'] = 'wow12345';$db['my_mssql']['database'] = '';$db['my_mssql']['dbdriver'] = 'odbc';$db['my_mssql']['dbprefix'] = '';$db['my_mssql']['pconnect'] = FALSE;$db['my_mssql']['db_debug'] = TRUE;$db['my_mssql']['cache_on'] = FALSE;$db['my_mssql']['cachedir'] = '';$db['my_mssql']['char_set'] = 'utf8';$db['my_mssql']['dbcollat'] = 'utf8_general_ci';$db['my_mssql']['swap_pre'] = '';$db['my_mssql']['autoinit'] = TRUE;$db['my_mssql']['stricton'] = FALSE;
Note:
SQL Server Native Client 11.0
or SQL Server Native Client 10.0
, just play with both settings.
Server=xx.xx.xx.x
usually is in the format Server=Host\Instance
The error is showing that SQLSRV driver implies the DLL is not loading ever. check your php_info() The SQLSRV driver requires for it.check this for step by step solution
https://futbolsalas15.wordpress.com/2014/02/23/7-steps-to-make-sql-server-and-codeigniter-works/