Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. $host = "db hostname";
  4. $dbname = "db name";
  5. $user = "db username";
  6. $pass = "db password";
  7. $charset = "UTF8MB4"; // if your db does not use CHARSET=UTF8MB4, you should probably be fixing that
  8.  
  9. $dsn = "mysql:host={$host};dbname={$dbname};charset={$charset}";
  10.  
  11. $options = [
  12. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // highly recommended
  13. PDO::ATTR_EMULATE_PREPARES => false // ALWAYS! ALWAYS! ALWAYS!
  14. ];
  15.  
  16. try {
  17. $pdo = new PDO( $dsn, $user, $pass, $options );
  18.  
  19. // now $pdo is ready for use!
  20.  
  21. } catch ( PDOException $e ) {
  22. // always catch PDOExceptions.
  23. // If there's a problem here, the error message will probably contain your DB password.
  24.  
  25. // log the error.
  26. // during development, if your server is not public, you can display the message instead if you prefer.
  27. error_log( $e->getMessage() );
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement