connect sql server php 1

connect sql server php

"dbName");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

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

Here is what the above code is Doing:
1. The sqlsrv_connect() function is used to establish a connection to a Microsoft SQL Server database.
2. The sqlsrv_errors() function returns an array of errors and warnings from the last sqlsrv operation performed.
3. The die() function prints a message and exits the current script.
4. The print_r() function prints human-readable information about a variable.
5. The true parameter of the print_r() function returns the information rather than print it.
6. The $serverName variable specifies the name of the server to which to connect.
7. The $connectionInfo variable specifies the connection options.
8. The $conn variable stores the connection information returned by sqlsrv_connect().
9. The if…else statement is used to check whether the connection was successful.
10. The echo statement is used to display the connection status.

Similar Posts