Advertisement
Guest User

Untitled

a guest
May 26th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. <?php
  2.  
  3. $path = dirname( __FILE__ );
  4.  
  5. require_once( $path . '/config.php');
  6.  
  7. abstract class DB
  8. {
  9. private static $conexao;
  10.  
  11. public static function connect()
  12. {
  13. if(!isset(self::$conexao))
  14. {
  15. try{
  16. self::$conexao = new PDO('mysql:host='.HOST.';dbname='.DB_NAME, USER, PASS);
  17. self::$conexao->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  18. self::$conexao->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
  19. }
  20. catch(PDOException $e)
  21. {
  22. echo $e->getMessage();
  23. }
  24. return self::$conexao;
  25. }
  26.  
  27. }
  28.  
  29.  
  30. public static function prepare($sql)
  31. {
  32. return self::connect()->prepare($sql);
  33. }
  34. }
  35.  
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement