Skip to content

Instantly share code, notes, and snippets.

@nzuwera
Created September 25, 2018 13:09
Show Gist options
  • Save nzuwera/337abfd10f6e5da102bc3f4ddac47fc2 to your computer and use it in GitHub Desktop.
Save nzuwera/337abfd10f6e5da102bc3f4ddac47fc2 to your computer and use it in GitHub Desktop.
/*
How to install and configure PHP to connect MSSQL on windows
Step 1: Download Microsoft ODBC related to Xampp or Wamp : https://www.microsoft.com/en-us/download/details.aspx?id=50420
Step 2: Download Microsoft SQL Driver for PHP related to your PHP version : https://docs.microsoft.com/en-us/sql/connect/php/sqlsrv-driver-api-reference?view=sql-server-2017
Step 3: Add the extracted dll file in php extentsion directory
Step 4: update php.ini to load the new extensions
Step 5: Restart Apache server
Step 6: Test connection below script. just remember to use the correct credentials for your database
*/
<?php
$server="DESKTOP-ODLPHLJ\\SQLEXPRESS";
$options = array("UID" => "<DB_USERNAME>","PWD" =>"<DB_PASSWORD>","Database"=>"<DATABASE_NAME>");
$conn = sqlsrv_connect($server,$options);
if ($conn === false) die("<pre>".print_r(sqlsrv_errors(), true));
echo "Successfully connected!";
sqlsrv_close($conn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment