Cannot Connect SQL Server database from PHP

Viewed 26

I'm trying to connect SQL Server from PHP 8.1 website which is hosted in a IIS Windows Server 2016 standard. I'm trying test the connection via this Code:

<?php

$configFilePath = 'SourceFiles\config\dbConfig.xml';
$SQLserverConfigFile = simplexml_load_file($configFilePath) or die("Error");
$serverInfo = $SQLserverConfigFile->SERV;
$credInfo = array();
        
$credInfo = array(
    "Database"  => (string) $SQLserverConfigFile->DB,
    "UID"       => (string) $SQLserverConfigFile->UID,
    "PWD"       => (string) $SQLserverConfigFile->PWD  
);

$query = "INSERT INTO [MIDAS_PADDS].[dbo].[RequestLog](email,formdata,time_stamp, submission_success) VALUES('test@test.com','Demo Data','2022-08-31 16:51:09.000','1')";


$conn = sqlsrv_connect($serverInfo, $credInfo);
if( $conn === false ) {
      echo print_r( sqlsrv_errors());
}
$result = sqlsrv_query($conn,$query);
sqlsrv_close($conn);

?>

I'm getting the following error:

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) ) 1

I've installed Microsoft® ODBC Driver 11 for SQL Server following a stackoverflow solution from this link: https://www.microsoft.com/en-us/download/details.aspx?id=36434.

But still getting the same error.

0 Answers
Related