dbConn = NULL; } public function __set($name, $value) { $this->$name = $value; } public function connect($dbHost='', $dbUser='', $dbPass='', $dbPort='', $dbName='') { if($dbHost == '' && $this->dbHost == '') $this->lastError = 'Please add a host name!'; if($dbUser == '' && $this->dbUser == '') $this->lastError = 'Please add a user name!'; if($dbPass == '' && $this->dbPass == '') $this->lastError = 'Please add a user password!'; if($dbPort == '' && $this->dbPort == '') $this->lastError = 'Please add a host port!'; if($dbName == '' && $this->dbName == '') $this->lastError = 'Please add a database name!'; if($this->lastError != '') return -1; try { $this->dbConn = new PDO("pgsql:host=". $this->dbHost .";port=". $this->dbPort .";dbname=". $this->dbName, $this->dbUser, $this->dbPass); $this->dbConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { $this->lastError = $e->getMessage(); return -1; } } public function connectByName($server) { switch($server) { case 'infectionData': $this->dbHost = '192.168.9.10'; $this->dbUser = 'drendler'; $this->dbPass = 'bXn8LV7ViZgAx6A'; $this->dbPort = '5432'; $this->dbName = 'CAMDPAMS'; $this->connect(); break; case 'trustedVendor': $this->dbHost = DBHOST; $this->dbUser = DBUSER; $this->dbPass = DBPASS; $this->dbPort = DBPORT; $this->dbName = DBNAME; $this->connect(); break; } } public function sqlExec($query, $params = '') { $stmt = ''; try { if($params != '') { $stmt = $this->dbConn->prepare($query); $stmt->execute($params); return $stmt->fetchAll(PDO::FETCH_ASSOC); }else{ $stmt = $this->dbConn->prepare($query); $stmt->execute(); return $stmt->fetchAll(PDO::FETCH_ASSOC); } } catch (PDOException $e) { $this->lastError = $e->getMessage(); return -1; } } public function getLastError() { return $this->lastError; } } ?>