Home >Database >Mysql Tutorial >Why am I getting a 'Call to undefined function sqlsrv_connect()' error in my XAMPP setup when connecting to SQL Server?
Debugging "Call to undefined function sqlsrv_connect()" Error in XAMPP for SQL Server Connection
Problem:
You encountered an error message "Fatal error: Call to undefined function sqlsrv_connect()..." when attempting to establish a database connection using the sqlsrv_connect() function.
Background:
The sqlsrv_connect() function is part of the SQLSRV extension for PHP, which allows you to connect to Microsoft SQL Server databases. This extension is not automatically installed in XAMPP versions 3.2.1 and above.
Solution:
To resolve this error, follow these steps:
Download and Install SQLSRV Extension:
Uncomment or Append SQLSRV Extension in php.ini:
Restart Apache in XAMPP:
Code Example:
After completing these steps, your code should look like the following:
<?php $serverName = "jy4nij6vuy.database.windows.net,1433"; $connectionOptions = array("Database" => "robertfarb", "UID" => "robertFarb", "PWD" => "******"); $conn = sqlsrv_connect($serverName, $connectionOptions); if ($conn === false) { die(print_r(sqlsrv_errors(), true)); } ?>
Additional Considerations:
The above is the detailed content of Why am I getting a 'Call to undefined function sqlsrv_connect()' error in my XAMPP setup when connecting to SQL Server?. For more information, please follow other related articles on the PHP Chinese website!