Call to undefined function sqlsrv_connect() in xampp

不羁的心 提交于 2019-12-12 15:02:26

问题


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 ?


回答1:


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




回答2:


  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



来源:https://stackoverflow.com/questions/33313823/call-to-undefined-function-sqlsrv-connect-in-xampp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!