Advertisement
Guest User

Untitled

a guest
May 10th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?
  2.  
  3. class MySQL extends PDO {
  4.     public function __construct($user,$pass,$dbname = null, $host = null, $port = null){
  5.         $dsn = array();
  6.        
  7.         // specify the host or socket
  8.         if(is_null($host)) $host = 'localhost';
  9.         if($host[0] === '/'){
  10.             $dsn[] = 'unix_socket='.$host;
  11.         }else{
  12.             $dsn[] = 'host='.$host;
  13.             // specify a port
  14.             if(!is_null($port) and is_int($port)) $dsn[] = 'port='.$port;
  15.         }
  16.        
  17.         // specify the db name
  18.         if(!is_null($dbname)) $dsn[] = 'dbname='.$dbname;
  19.        
  20.         // make connection
  21.         parent::__construct('mysql:'.implode($dsn,';'), $user, $pass);
  22.     }
  23. }
  24.  
  25. class pgSQL extends PDO {
  26.     public function __construct($user,$pass,$dbname, $host = null, $port = null){
  27.         $dsn = array();
  28.        
  29.         // specify the host or socket
  30.         if(!is_null($host)) $dsn[] = 'host='.$host;
  31.         // specify a port
  32.         if(!is_null($port) and is_int($port)) $dsn[] = 'port='.$port;
  33.         // specify the db name
  34.         $dsn[] = 'dbname='.$dbname;
  35.         // specify the user and password
  36.         $dsn[] = 'user='.$user;
  37.         $dsn[] = 'password='.$pass;
  38.        
  39.         // make connection
  40.         parent::__construct('pgsql:'.implode($dsn,' '));
  41.     }
  42. }
  43.  
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement