single.php
First of all create a php file with the below code.
phpinfo();
Run the file after saving. Find out the version of php installed, from the info screen which is opened. Find out the Architecture ( X86 or X64 ). Now find out thread safety from the page (enabled or disabled.
After getting all the informations from the file, You need to download php_sqlsrv
file from internet. Choose the correct option using the informations that you collected from the info file. Download and install the file.
After installation go to the server folder, then open php folder and then ext folder. There you can find php_sqlsrv
like file. Now go to the XAMP control panel, and open the php.ini file.
Open php.ini file search for “extensions”. There you can find some extensions are added. Place extension=php_sqlsrv.dll
code in this portion. Remember this should match the filename which you found in the ext folder. Better copy the file name from ext and paste here.
Now go to XAMP control panel and restart Apache. Run that phpinfo()
file once again. Search for sqlsrv
area in that file. If you can find this in the file, your installation is access. Else don’t worry check the version of sqlsrv
installed. Get the correct version that matches the configuration of the php.
After successfull installation yopu need one more software to install. That is ODBC driver for php. Get the ODBC driver for php from internet. Check your computers configuration (32bit or 64bit).This information is available by opening computer management ( Right click on my computer select Management). Get the correct version of ODBC driver for php from internet and install it.
Now your Apache is ready to communicate with MSSQL
Write the code for communication.
$myServer = "192.168.2.143";
$myUser = "sa";
$myPass = "sa";
$myDB = "db_tracking";
$connectionInfo = array("Database" =--> $myDB, "UID" => $myUser, "PWD" => $myPass);
$conn = sqlsrv_connect($myServer, $connectionInfo); //returns false
if ($conn === false) {
echo "failed connection";
}
$sql = "SELECT DISTINCT(EmpName),EmpOnlineStatus FROM tbl_EmpDetails where EmpOnlineStatus=1";
$stmt = sqlsrv_query($conn, $sql);
if (sqlsrv_fetch($stmt) === false) {
echo "couldn't fetch data";
}
sqlsrv_close($conn);
Give correct parameters like $myServer
( Where your MSSQL Database is ), $myDB
(Database Name) etc.