Advertisement
Guest User

Untitled

a guest
Feb 19th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <?php
  2. class BddClass {
  3.  
  4. public $bdd = null;
  5.  
  6. public function __construct() {
  7. $hostname = "localhost";
  8. $dbname = "common-database";
  9. $username = "root";
  10. $password = "password";
  11.  
  12. try {
  13. $this->bdd = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
  14. $this->bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  15. } catch (PDOException $e) {
  16. $this->bdd = null;
  17. die($e->getMessage());
  18. }
  19. }
  20.  
  21. public function get_error() {
  22. $this->bdd->errorInfo();
  23. }
  24.  
  25. public function __destruct() {
  26. $this->bdd = null;
  27. }
  28.  
  29. public static function getConnection() {
  30. return new BddClass();
  31. }
  32.  
  33. public function lastInsertId(){
  34. return $this->bdd->lastInsertId();
  35. }
  36. }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement