Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. <?php
  2. // Connection variables.
  3. $db_type = "";
  4. $db_host = "";
  5. $db_user = "";
  6. $db_password = "";
  7. $db_database = "";
  8.  
  9. // We test the connection with the database.
  10. try
  11. {
  12. $db = new PDO($db_type.":host=".$db_host.";dbname=".$db_database, $db_user, $db_password);
  13. }
  14. catch (Exception $e)
  15. {
  16. // If the current user has the administrator status, we display the
  17. // complete error message.
  18. if (isset($_SESSION['status']) && $_SESSION['status'] == 'admin')
  19. die("Error : " . $e->getMessage());
  20. // Else, we display a generic error message with no details.
  21. else
  22. die("Error : Impossible to establish the connection with the database.");
  23. }
  24.  
  25. // Used to handle database error messages.
  26. function mySqlError($db)
  27. {
  28. // If the current user has the administrator status, we display the
  29. // complete error message.
  30. if (isset($_SESSION['status']) && $_SESSION['status'] == 'admin')
  31. print_r($db->errorInfo());
  32. // Else, we display a generic error message with no details.
  33. else
  34. echo "Error : Sorry, an SQL error has occured.";
  35. }
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement