db_host == '') { $local_connection_string .= "host=$this->db_host "; } $local_connection_string = "dbname=$this->db_name user=$this->db_user "; if ($this->db_password == '') { $local_connection_string .= $this->db_password; } $this->db_connection = pg_pconnect($local_connection_string); if ($this->have_db_connection() == FALSE) { syslog (LOG_INFO, "Failed to make a connection to Postgres"); die ("connection to Postgres failed\n"); } else { syslog (LOG_INFO, "Connection to Postgres was made correctly"); } } function have_db_connection () { /* This simple function verifies if a connection has succesfully been made * Output: Returns TRUE if the connection was successfully (else it will be FALSE) */ // PHP-> 4.2.Xcode if (pg_connection_status($this->db_connection) == PGSQL_CONNECTION_BAD) { if ($this->db_connection == '') { return "FALSE"; } else { return "TRUE"; } } function query ($inp_sql_query) { /* This function executes a query against the active database connection * INPUT: * - $inp_sql_query: The is the string with the SQL to execute * OUTPUT: Resultstring */ $this->db_result = pg_exec ($this->db_connection, $inp_sql_query); $this->db_row_number = 0; } function fetch_row() { /* This function returns a single row as a result of a query if the last record has been reached * the result will be FALSE otherwise it will be TRUE * INPUT : NONE (everything is available within the class) * OUTPUT : Success TRUE/FALSE * VALUES SET : */ unset ($this->db_result_row); if (pg_numrows($this->db_result) < $this->db_row_number) { $this->db_row_number=-1; return "FALSE"; } else { $this->db_result_row = pg_fetch_row($this->db_result); return "TRUE"; } } function num_rows() { /* This functions returns the number of rows in a resultset * INPUT : NONE * OUTPUT : Number of rows (number) */ return pg_numrows($this->db_result); // 4.2.X return pg_num_rows($this->db_result); } function num_fields() { /* This function returns the number of fields in the resultset * INPUT : NONE * OUTPUT : Number of fields (number) */ return pg_numfields($this->db_result); //4.2.X return pg_num_fields($this->db_result); } } ?>