0

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.

Rafiq Reefat
  • 29
  • 1
  • 4
  • Is that the correct version? https://learn.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?redirectedfrom=MSDN&view=sql-server-ver16#odbc-driver And correct bitness (x86 vs x64) to match the PHP process. – David Browne - Microsoft Sep 10 '22 at 19:03
  • I've followed this solution : https://stackoverflow.com/questions/42768483/cannot-connect-to-sql-server-in-php I've installed x64 – Rafiq Reefat Sep 10 '22 at 19:07
  • 2
    You should follow the docs: https://learn.microsoft.com/en-us/sql/connect/php/step-1-configure-development-environment-for-php-development?view=sql-server-ver16 – David Browne - Microsoft Sep 10 '22 at 19:12
  • Thanks. Installed the Microsoft® ODBC Driver 17 Solved the issue. – Rafiq Reefat Sep 11 '22 at 12:40

0 Answers0