Guest User

Untitled

a guest
May 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. $serverName = "IP OF MY SERVER";
  2. $connectionOptions = array(
  3. "Database" => "DB NAME",
  4. "Uid" => "USER",
  5. "PWD" => "PASSWORD"
  6. );
  7. //Establishes the connection
  8. $conn = sqlsrv_connect($serverName, $connectionOptions);
  9. //Select Query
  10. $tsql = "SELECT @@Version as SQL_VERSION";
  11. //Executes the query
  12. $getResults = sqlsrv_query($conn, $tsql);
  13. //Error handling
  14.  
  15. if ($getResults == FALSE)
  16. die(FormatErrors(sqlsrv_errors()));
  17.  
  18. sqlsrv_free_stmt($getResults);
  19.  
  20. function FormatErrors($errors) {
  21. /* Display errors. */
  22. /* echo "Errors: <br/>";
  23.  
  24. foreach ($errors as $error) {
  25. echo "SQLSTATE: " . $error['SQLSTATE'] . "<br/>";
  26. echo "Code: " . $error['code'] . "<br/>";
  27. echo "Message: " . $error['message'] . "<br/>";
  28. }
  29. }
Add Comment
Please, Sign In to add comment