Search code examples
phpsql-server-2014ampps

cannot connect to database with sqlserver?


I have ampp3.9-PHP7.3 and SQLserver-2014 12.0.2269.0. I am not able to connect the database. I getting the following error

Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in E:\Ampps\Ampps\www\backend scripts\database.php:4 Stack trace: #0 {main} thrown in E:\Ampps\Ampps\www\backend scripts\database.php on line 4

Here is my code

<?php
$serverName = "DESKTOP-VDSPQT9"; //serverName\instanceName
$connectionInfo = array( "Database"=>"railway", "UID"=>"sa", "PWD"=>"bhanu123");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

Solution

  • I believe that you should install the driver.

    https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=20098