Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Connection variables.
- $db_type = "";
- $db_host = "";
- $db_user = "";
- $db_password = "";
- $db_database = "";
- // We test the connection with the database.
- try
- {
- $db = new PDO($db_type.":host=".$db_host.";dbname=".$db_database, $db_user, $db_password);
- }
- catch (Exception $e)
- {
- // If the current user has the administrator status, we display the
- // complete error message.
- if (isset($_SESSION['status']) && $_SESSION['status'] == 'admin')
- die("Error : " . $e->getMessage());
- // Else, we display a generic error message with no details.
- else
- die("Error : Impossible to establish the connection with the database.");
- }
- // Used to handle database error messages.
- function mySqlError($db)
- {
- // If the current user has the administrator status, we display the
- // complete error message.
- if (isset($_SESSION['status']) && $_SESSION['status'] == 'admin')
- print_r($db->errorInfo());
- // Else, we display a generic error message with no details.
- else
- echo "Error : Sorry, an SQL error has occured.";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement