4

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 ?

amdixon
  • 3,814
  • 8
  • 25
  • 34
J Wayne
  • 51
  • 1
  • 1
  • 4

2 Answers2

2

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

Ravish
  • 2,383
  • 4
  • 37
  • 55
0
  1. Figure out which version of PHP you are using.Download Microsoft Drivers for PHP for SQL Server
  2. After knowing which version of driver you need, based on version of PHP, just copy that DLL file into the EXT subfolder of your PHP installation. I suppose that woule be c:\php5\ext
  3. Edit your php.ini file. It shall reside either in your c:\Windows or in your c:\php5 folder (again based on PHP installation). You may check where this file is loaded from again from the PHP Info function output (phpinfo()), there is a line like this: Loaded Configuration File C:\php5\php.ini
  4. Once you edit your php.ini to load the appropriate file, restart your web server to make it reload the new php.ini
  5. Check again the output from phpinfo()! Repeat 1 to 4 until you see "sqlsvr" in "Registered PHP Streams" line of phpinfo() output.

Your driver is not properly loaded, and you will not see any warnings for this (besides the Fatal Error for "call to undefined function") until you see "sqlsvr" as part of Registered PHP Streams in the output of phpinfo().

for more these are some SO links:

Connect sqlsrv in Xampp

Fatal error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs

hope this helps

Community
  • 1
  • 1
Linus
  • 899
  • 3
  • 19
  • 33
  • Thanks. Now I fix above error but now I'm facing with new 'Unable to connect to your database server using the provided settings. Filename: D:/xampp/htdocs/doorlock/application/controllers/login.php Line Number: 7' – J Wayne Oct 24 '15 at 09:11
  • @JWayne it may be due database credentials issue check username password etc – Linus Oct 24 '15 at 09:28
  • I checked . But I can't connect . How do think about that – J Wayne Oct 24 '15 at 10:06
  • @JWayne plz edit your question and post login.php code too – Linus Oct 24 '15 at 10:08