Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <?php
  2. // Defines database connection information
  3. $settings = [
  4. 'host' => '127.0.0.1',
  5. 'name' => 'c9',
  6. 'port' => '3306',
  7. 'charset' => 'utf8',
  8. 'username' => 'admin',
  9. 'password' => 'root'
  10. ];
  11. ?>
  12.  
  13. <?php
  14. // Includes database connection information
  15. require_once('../settings.php');
  16.  
  17. // Establishes connection to database server
  18. try {
  19. $dbh = new PDO(
  20. sprintf(
  21. 'mysql:host=%s;dbname=%s;port=%s;charset=%s',
  22. $settings['host'],
  23. $settings['name'],
  24. $settings['port'],
  25. $settings['charset']
  26. ),
  27. $settings['username'],
  28. $settings['password']
  29. );
  30. // Prevents emulated prepare statements and sets error mode
  31. // to PDO::ERRMODE_EXCEPTION
  32. $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  33. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  34. }
  35. // Prints out errors raised by PDO
  36. catch (PDOException $e) {
  37. die('Error: ' . $e->getMessage());
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement