Advertisement
Guest User

Untitled

a guest
Oct 28th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. class DB {
  5. private $conn;
  6. private $servername = "localhost";
  7. private $username = "user";
  8. private $password = "pass";
  9. private $charset = "UTF8MB4"; // if your db does not use CHARSET=UTF8MB4, you should probably be fixing that
  10. private $options = [
  11. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // highly recommended
  12. PDO::ATTR_EMULATE_PREPARES => false // ALWAYS! ALWAYS! ALWAYS!
  13. ];
  14.  
  15.  
  16. public function __construct(){
  17. try {
  18. $dns = "mysql:host=$this->servername;dbname=$this->username;charset=$this->charset";
  19. $this->conn = new PDO($dns, $this->username, $this->password,$this->options);
  20.  
  21. } catch(PDOException $e){
  22. echo "Connection failed: " . $e->getMessage();
  23. }
  24.  
  25. }
  26. }
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement