3

I am running on:

  • Windows Server 2016 64-bit
  • MSSQL Server 2016 on the same server
  • PHP 7.1
  • IIS 10

I have:

  • Made sure I can connect to my SQL using the credentials supplied in the codes below.
  • Installed SQL Server Driver from for PHP from Microsoft, and chose SQLSRV40
  • Added extension=php_sqlsrv_7_nts_x64.dll and extension=php_pdo_sqlsrv_7_nts_x64.dll to /ext folder.
  • edited my php.ini and added extension=php_sqlsrv_7_nts_x64.dll and extension=php_pdo_sqlsrv_7_nts_x64.dll and restarted the server.

The following are my code to establish connection:

$connectionInfo = array( "Database"=>$db, "UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect( $serverName, $connectionInfo); 

if( $conn ) {
     echo "Connection established.<br />";
}else{ //Will not execute. As such, I have no idea what error(s) am I getting
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}

Executing phpinfo() does not show the sqlsrv. However, executing the following code will display a YES.

echo "Did it load? " . extension_loaded('php_sqlsrv_7_nts_x64.dll') ? "YES" : "NO";

I have worked on this for 2 days, and have followed many forums suggestions, and I have no idea what to try anymore. Would appreciate any advise from you experts! :)

Update 1:

I modified the codes below, and it shows a NO.

echo "Did it load? " . (extension_loaded('sqlsrv') ? "YES" : "NO");
echo "Did it load? " . (extension_loaded('pdo_sqlsrv') ? "YES" : "NO");

I don't understand why is it not installed correctly where the dll has already been put inside the extension folder, and specified inside php.ini as I stated earlier.

Syah
  • 463
  • 5
  • 13
  • `extension_loaded()` expects the *name* of the extension not the dll file name... so it should be `extension_loaded('sqlsrv')` or `extension_loaded('pdo_sqlsrv')`. Also your test will always display `YES`, you need to wrap the ternary expression in parenthesis [see this answer](http://stackoverflow.com/a/1317385/3760604). – ImClarky Jan 25 '17 at 09:46
  • @ImClarky Oh no... I have replaced it with just extension name, and added parenthesis. Now, the strings are displaying correctly and it shows a NO. Why is it NO? I have already put the dll inside the extension folder and added it into my php.ini. What else am I missing? – Syah Jan 26 '17 at 10:11
  • have a look at [this answer I posted](http://stackoverflow.com/a/41893883/3760604). The OP seems to be having the same issue as yourself. – ImClarky Jan 27 '17 at 12:21
  • It worked!! You can either post this as answer or I'll update my post to update to your suggested post! :) – Syah Jan 28 '17 at 13:47

0 Answers0