69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
<?php
|
|
|
|
class Db {
|
|
|
|
private $conn;
|
|
private $conn_gps;
|
|
|
|
public function __construct() {
|
|
}
|
|
/*
|
|
'DSN' => '',
|
|
'hostname' => '10.10.33.21',
|
|
'username' => 'savvy',
|
|
'password' => 'savvy001!',
|
|
'database' => 'savvy',
|
|
'DBDriver' => 'Postgre',
|
|
'DBPrefix' => '',
|
|
|
|
gpsdatabase:
|
|
{
|
|
host = "172.31.12.248";
|
|
name = "savvy_gps";
|
|
user = "savvy";
|
|
pass = "savvy001!";
|
|
port = 5432;
|
|
};
|
|
*/
|
|
public function getConnect() {
|
|
global $savvyext;
|
|
if ($this->conn==NULL || !pg_version($this->conn)) {
|
|
$db_host ='10.10.33.21'; //$savvyext->cfgReadChar('database.host');
|
|
$db_name = 'savvy'; // $savvyext->cfgReadChar('database.name');
|
|
$db_user = 'savvy'; //$savvyext->cfgReadChar('database.user');
|
|
$db_pass = 'savvy001!'; // $savvyext->cfgReadChar('database.pass');
|
|
$db_port = '5432'; //$savvyext->cfgReadLong('database.port');
|
|
$connstr = "host=${db_host} port=${db_port} dbname=${db_name} user=${db_user} password=${db_pass}";
|
|
$this->conn = pg_connect($connstr);
|
|
}
|
|
return $this->conn;
|
|
}
|
|
|
|
public function getConnectGPS() {
|
|
global $savvyext;
|
|
if ($this->conn_gps==NULL || !pg_version($this->conn_gps)) {
|
|
$db_host = $savvyext->cfgReadChar('gpsdatabase.host');
|
|
$db_name = $savvyext->cfgReadChar('gpsdatabase.name');
|
|
$db_user = $savvyext->cfgReadChar('gpsdatabase.user');
|
|
$db_pass = $savvyext->cfgReadChar('gpsdatabase.pass');
|
|
$db_port = $savvyext->cfgReadLong('gpsdatabase.port');
|
|
$connstr = "host=${db_host} port=${db_port} dbname=${db_name} user=${db_user} password=${db_pass}";
|
|
$this->conn_gps = pg_connect($connstr);
|
|
}
|
|
return $this->conn_gps;
|
|
}
|
|
|
|
function __destruct() {
|
|
if(!empty($this->conn)){
|
|
pg_close($this->conn);
|
|
}
|
|
if(!empty($this->conn_gps)){
|
|
pg_close($this->conn_gps);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
// vi:ts=2
|
|
|