Advertisement
kilykil

1connection

Jun 18th, 2017
108
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.  
  3. $database = new database;
  4.  
  5. ob_start();
  6. session_start();
  7.  
  8. //dont show notice error
  9. error_reporting(E_ALL & ~E_NOTICE);
  10.  
  11. class database {
  12.  
  13. private $pdo;
  14.  
  15. public function __construct() {
  16. // Connection information
  17. $host = 'localhost';
  18. $dbname = '';
  19. $user = 'root';
  20. $pass = '';
  21.  
  22. // Attempt DB connection
  23. try
  24. {
  25.  
  26. $this->pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
  27. $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  28. // check if db connection is succesful
  29. // echo 'Successfully connected to the database!';
  30. }
  31. catch(PDOException $e)
  32. {
  33. echo $e->getMessage();
  34. }
  35.  
  36. }
  37. }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement