Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. namespace App\Core;
  5.  
  6.  
  7. abstract class Model {
  8.  
  9. protected static function getDB() {
  10. static $db = null;
  11.  
  12. if($db === null){
  13.  
  14. $host = 'localhost';
  15. $dbname = 'test';
  16. $username = 'root';
  17. $password = '';
  18.  
  19. try{
  20. $db = new \PDO("mysql:host={$host};dbname={$dbname};", $username, $password, array(
  21. \PDO::ATTR_PERSISTENT => true));
  22. return $db;
  23. }catch (\PDOException $e){
  24. echo $e->getMessage();
  25. }
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement