# Cannot Connect To MSSQL Server

I am using php 7 and trying to connect to mssql server. I have this code:

<?php
$serverName = "server"; //serverName\instanceName$connectionInfo = array( "Database"=>"database", "UID"=>"userid", "PWD"=>"password");
$conn = sqlsrv_connect($serverName, $connectionInfo); if($conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>


but when I open the page, I get this error

Call to undefined function SQLSRV_CONNECT()

Is it an issue with the php version or simply an additional package that I should add to my Joomla install?

As @Sharky said, it seems like your SQLSRV extension isn't enabled. You can manually activate it by changing your php.ini file, enabling this extension and downloading the drivers.

PHP Documentation says:

The SQLSRV extension is enabled by adding appropriate DLL file to your PHP extension directory and the corresponding entry to the php.ini file. The SQLSRV download comes 8 driver files, four of which are for PDO support.

Once you have downloaded the file, you have to execute it. A box will prompt asking where you want to extract.

You can extract to wherever you want to and then copy to your php extension folder or you can directly extract to your PHP extension folder. Usually your extension folder lies in: your-php-folder\bin\php\your-php-version or your-php-folder\bin\php and it's called ext. So the final path is something like this: your-php-folder\bin\php\ext.

To enable the dll in your php.ini file, you have to open it, and search for Extensions then add the dll like this:

extension=name-of-your-dll-you-downloaded-and-extracted-to-the-ext-folder.dll


Example:

extension=php_sqlsrv_81_s.dll


If that doesn't work, you can try simply extension=sqlsrv_81_s leaving out php_ and .dll

• I add the downloaded files to my extensions directory. What do I modify my php.ini file to? I'm not clear on what I need to add to that – jamesMandatory Jul 3 at 18:24
• I updated my answer. – Thiago Guimarães Jul 3 at 18:34

Your issue is not related to Joomla. You are manually calling a function which does not exist on your PHP installation. This most likely means the required SQLSRV PHP extension is not enabled.

• once I SSH into the box, what command do i run to enable this function? – jamesMandatory Jul 2 at 16:49

If you Joomla work and need to access the database use Joomla functional to connect database

\$db = JFactory::getDbo();

• Hello Dmitry, in this case he's trying to connect to the database using MSSQL. So he has to set up an environment first before start using MSSQL Server. But it seems like he managed to solve his problem. – Thiago Guimarães Jul 8 at 16:11