Advertisement
Guest User

Untitled

a guest
Sep 16th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <?php
  2. function connection() {
  3. try {
  4. $host = "localhost";
  5. $charset = "utf8";
  6. $user = "my_username";
  7. $pass = "my_pass";
  8. $db = "my_db_name";
  9. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  10.  
  11. $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
  12. $conn = new PDO ($dsn, $user, $pass, $options);
  13.  
  14. } catch (PDOException $e) {
  15. $output = "We are unable to connect from database";
  16. $file = "error_log.php";
  17. $err_msg = $e->getMessage() " This error occured on <?php echo date("d/m/y i:m:s A");?>";
  18. file_put_contents($file, $err_msg);
  19. include 'inc/script-error.php';
  20. }
  21. $output = "Connection with database was successfull.";
  22. include 'inc/script-success.php';
  23. }
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement