3

I've got the following code in my Wordpress file:

$sql_server_2008 = sqlsrv_connect(
    '$ip',
    array(
        'Database'=>'$database_name',
        'UID'=>'$uid',
        'PWD'=>'$password'
    )
);

and I'm getting the following error:

Fatal error: Call to undefined function sqlsrv_connect()

I'm running Wamp with PHP 5.6.25, so I've installed the 5.6 versions of the SQL Server drivers. From PHP.ini:

extension=php_pdo_sqlsrv_56_nts.dll
extension=php_pdo_sqlsrv_56_ts.dll
extension=php_sqlsrv_56_nts.dll
extension=php_sqlsrv_56_ts.dll

and they're showing as active in the Wamp UI:

Screenshot showing the active extensions

So why isn't it working?

EDIT: They're not showing up in loaded extensions.

$extensions = get_loaded_extensions (); 
print_r($extensions);

Returns:

Array ( [0] => Core [1] => bcmath [2] => calendar [3] => ctype [4] => date [5] => ereg [6] => filter [7] => ftp [8] => hash [9] => iconv [10] => json [11] => mcrypt [12] => SPL [13] => odbc [14] => pcre [15] => Reflection [16] => session [17] => standard [18] => mysqlnd [19] => tokenizer [20] => zip [21] => zlib [22] => libxml [23] => dom [24] => PDO [25] => bz2 [26] => SimpleXML [27] => wddx [28] => xml [29] => xmlreader [30] => xmlwriter [31] => apache2handler [32] => Phar [33] => curl [34] => com_dotnet [35] => fileinfo [36] => gd [37] => gettext [38] => gmp [39] => intl [40] => imap [41] => ldap [42] => mbstring [43] => exif [44] => mysql [45] => mysqli [46] => pdo_mysql [47] => pdo_sqlite [48] => soap [49] => sockets [50] => sqlite3 [51] => xmlrpc [52] => xsl [53] => mhash [54] => Zend OPcache [55] => xdebug )
Sinister Beard
  • 3,570
  • 12
  • 59
  • 95

2 Answers2

0

The fact that your GUI marks them as "installed" means little. The GUI tool might think they are installed, while they are not. For PHP to use extensions, they need to be specified either in the PHP.INI file, or in a file loaded by PHP.INI. Also, it is possible that if they're specified in both, only one is actually working.

Using phpinfo() you can retrieve the location of php.ini, which you can open using any \n-compliant text editor (so, Wordpad, not Notepad) to see what is really there.

Then you need to check how it's loading the extensions.

For example phpinfo might say:

Loaded Configuration File => /etc/php5/apache2/php.ini

Scan this dir for additional .ini files => /etc/php5/common/modules

Here it means that you ned to check that PHP.ini, plus all INI files in the directory modules. Your paths will vary, of course.

Either in PHP.INI or in, say, modules/SQLSERV.INI (name is ignored, but the extension must be .ini), you will need to have something like

extension=php_sqlsrv_56_ts.dll
extension=php_pdo_sqlsrv_56_ts.dll

Then, these DLLs (your DLLs might be different, and you'll have one for each driver you install) will need to be there, and be the correct version. You should get a message if this is not so, but the message might be lost in some logfile somewhere. So you'll need to check the configuration and see whether such a message is displayed.

In a pinch, you can try and set a wrong DLL to see whether that elicits some recognizable error behaviour. If it does, you'll be sure that the line is parsed, and therefore not having that behaviour means the line is okay.

LSerni
  • 55,617
  • 10
  • 65
  • 107
-2

The MSSQL extension is not available anymore on Windows with PHP 5.3 or later. SQLSRV, an alternative driver for MS SQL is available from Microsoft: » http://www.microsoft.com/en-us/download/details.aspx?id=20098

Original Answer :

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

Community
  • 1
  • 1
Vasim Shaikh
  • 4,485
  • 2
  • 23
  • 52