Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- class MySQL extends PDO {
- public function __construct($user,$pass,$dbname = null, $host = null, $port = null){
- $dsn = array();
- // specify the host or socket
- if(is_null($host)) $host = 'localhost';
- if($host[0] === '/'){
- $dsn[] = 'unix_socket='.$host;
- }else{
- $dsn[] = 'host='.$host;
- // specify a port
- if(!is_null($port) and is_int($port)) $dsn[] = 'port='.$port;
- }
- // specify the db name
- if(!is_null($dbname)) $dsn[] = 'dbname='.$dbname;
- // make connection
- parent::__construct('mysql:'.implode($dsn,';'), $user, $pass);
- }
- }
- class pgSQL extends PDO {
- public function __construct($user,$pass,$dbname, $host = null, $port = null){
- $dsn = array();
- // specify the host or socket
- if(!is_null($host)) $dsn[] = 'host='.$host;
- // specify a port
- if(!is_null($port) and is_int($port)) $dsn[] = 'port='.$port;
- // specify the db name
- $dsn[] = 'dbname='.$dbname;
- // specify the user and password
- $dsn[] = 'user='.$user;
- $dsn[] = 'password='.$pass;
- // make connection
- parent::__construct('pgsql:'.implode($dsn,' '));
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement