Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2.  
  3. class MySQlDB {
  4.  
  5. private $user;
  6. private $pass;
  7. private $host;
  8. private $base;
  9. private $file;
  10. public $pdo;
  11.  
  12. public function __construct(){
  13. try{
  14. $this->user = 'root';
  15. $this->pass = '';
  16. $this->host = 'localhost';
  17. $this->base = 'benedelle'; //benedelle
  18.  
  19. $params = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8');
  20. $this->file = 'mysql:host='.$this->host.';dbname='.$this->base;
  21. $this->pdo = new PDO($this->file, $this->user, $this->pass, $params);
  22. $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  23. $this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  24. $this->pdo->setAttribute(PDO::ATTR_PERSISTENT, true);
  25. if(!$this->pdo){
  26. echo "Erro na conexão com o Banco de Dados";
  27. }
  28. return $this->pdo;
  29. }catch(PDOException $ex){
  30. echo "Erro no sistema: " . $ex->getMessage()."<br>";
  31. }
  32. }
  33.  
  34. /* Constante para Acessar de Outras Classes
  35. * @CONSTANT
  36. */
  37. public static $system = 'solid_'; //CONSTANTE
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement