Call to undefined function sqlsrv_connect() in xampp

J Wayne picture J Wayne · Oct 24, 2015 · Viewed 19.2k times · Source

When I tried to connect sqlsrv server in codeigniter, I got this error message.

Call to undefined function sqlsrv_connect() in xampp

Below is codes from database.php

$db['default'] = array(
'dsn'   => '',
'hostname' => 'MainDS\WTInfoUnit',
'username' => 'sa',
'password' => 'crafter',
'database' => 'BioStar_DoorLog',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE

Can anyone help ?

Answer

Ravish picture Ravish · Oct 24, 2015

In order to be able to use sqlsrv_* functions, you need to have the Microsoft SQL Server drivers for PHP. SQL Server drivers are not included by default in PHP Package, and developers need to add them to their php installations.

Follow Microsoft guide for installing SQL Server Driver for PHP:

https://msdn.microsoft.com/en-us/library/cc296203%28v=sql.105%29.aspx

You can download the drivers from Microsoft site:

https://www.microsoft.com/en-us/download/details.aspx?id=20098

Make you reference correct php_sqlsrv_YOUR_PHP_VERSION_ts.dll in your php.ini

-Thanks