connection = false; $this -> queryresult = false; $this -> errormessage = ""; $this -> rowcount = 0; $this -> colcount = 0; } //constructor function pgsql_base( $_dbname = "",$_dbuser = "") { $this -> dbname = $_dbname; $this -> dbuser = $_dbuser; $this -> init(); } //connect Database function connect() { $ret_code = false; $s = ""; if ($this -> dbhost != "") { $s .= "host=".$this -> dbhost; }; if ($this -> dbport != "") { $s .= " port=".$this -> dbport; }; if ($this -> dbname != "") { $s .= " dbname=".$this -> dbname; }; if ($this -> dbuser != "") { $s .= " user=".$this -> dbuser; }; if ($this -> dbpassword != "") { $s .= " password=".$this -> dbpassword; }; // connecting database if ($this -> connection) $this->close(); $this -> connection = pg_connect($s); if (!$this -> connection){ $this -> errormessage = "DB接続に失敗しました."; } else { $ret_code = $this -> connection; $this -> errormessage = "DB接続に成功しました."; } return $ret_code; } //close Database function close() { if ($this -> connection) pg_close($this -> connection); $this -> init(); return true; } //execute query function execute($str_query) { $ret_code = false; $this -> errormessage = ""; if (!$this -> connection) { $this -> errormessage = "DBに接続していません."; } else { //free result memorys if ($this -> queryresult) { //pg_freeresult($this -> queryresult); // - php4.2.0 pg_free_result($this -> queryresult); // php4.2.0- $this -> queryresult = false; }; //execute query //$this -> queryresult = pg_exec($this -> connection, $str_query); // - php4.2.0 $this -> queryresult = pg_query($this -> connection, $str_query); // php4.2.0 - if (!$this -> queryresult) { $this -> errormessage = "クエリ実行に失敗しました.\n原因: ".pg_result_error($this->connection); } else { $ret_code = $this -> queryresult; //get result information //$this -> rowcount = pg_numrows($this -> queryresult); // - php4.2.0 $this -> rowcount = pg_num_rows($this -> queryresult); // php4.2.0 - //$this -> colcount = pg_numfields($this -> queryresult); // - php4.2.0 $this -> colcount = pg_num_fields($this -> queryresult); // php4.2.0 - }; } return $ret_code; } } ?>