21 require_once (dirname(__FILE__) .
'/../TestEnvironment.php');
22 require_once (dirname(__FILE__) .
'/../../ui/common/common-ui.php');
38 function __construct($options = NULL) {
43 if (is_null($options)) {
45 $this->dbHost =
'localhost';
47 $this->dbUser = $USER;
48 $this->dbPassword = $PASSWORD;
55 if(is_resource($this->_pg_conn)) {
65 public function get_pg_ERROR() {
66 return($this->pg_ERROR);
79 public function connect($options = NULL) {
80 if (is_resource($this->_pg_conn)) {
81 return ($this->_pg_conn);
85 return ($this->_pg_conn);
99 private function _docon($options = NULL) {
101 $dbname =
'fossology';
103 if (is_null($options)) {
104 $this->_pg_conn = pg_pconnect(
"host=$this->dbHost dbname=$dbname " .
105 "user=$this->dbUser password=$this->dbPassword");
108 $this->_pg_conn = pg_pconnect(str_replace(
";",
" ", $options));
110 $res = pg_last_error($this->_pg_conn);
112 if(is_null($this->_pg_conn)) {
113 $this->pg_Error = TRUE;
114 print
"DB: could not connect to the db, connection is NULL\n";
118 if($this->_pg_conn === FALSE) {
119 $this->pg_Error = TRUE;
120 print
"DB: could not connect to the db, connect is FALSE\n";
123 if (!isset ($this->_pg_conn)) {
148 $uid = posix_getuid();
149 $uidInfo = posix_getpwuid($uid);
150 $this->pg_rows = array ();
151 if (!$this->_pg_conn) {
152 return ($this->pg_rows);
155 return ($this->pg_rows);
158 @ $result = pg_query($this->_pg_conn, $Sql);
162 $this->pg_rows = pg_affected_rows($result);
165 if (!isset ($result)) {
166 print
"DB-Query: result not set!\n";
169 @ $rows = pg_fetch_all($result);
171 if (!is_array($rows)) {
175 @ pg_free_result($result);
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.