Location: PHPKode > scripts > Access Data Object > access-data-object/postgres.php
<?php
	require_once('ado.php');
	class postgres extends ado{
		function db_connect() {
			$this->host = "10.79.6.46";
			$this->banco = "vinnydb";
			$this->user = "vinny";
			$this->senha = "vinicius";
			if ($conn = pg_connect("host=$this->host dbname=$this->banco user=$this->user password=$this->senha")) {
				return $conn;
			}
			else {
				return false;
			}
		}

		function db_close($conn) {
			if (pg_close($conn)) {
				return true;
			}
			else {
				return false;
			}
		}

		function query($sql) {
			$this->conn = $this->db_connect() or die ("Não é possível connectar ao banco de dados.");
			if ($res = pg_query($this->conn,$sql)) {
				pg_close($this->conn);
				return $res;
			}
			else {
				pg_close($this->conn);			
				return false;
			}
		}

		function to_array($res) {
			if ($linha = pg_fetch_array($res)) {
				return $linha;
			}
			else {
				return false;
			}
		}
		
		function num_rows($res) {
			if ($num = pg_num_rows($res)) {
				return $num;
			}
			else {
				return false;
			}
		}

		function num_fields($res) {
			if ($num = pg_num_fields($res)) {
				return $num;
			}
			else {
				return false;
			}
		}

		function affected_rows($res) {
			if ($num = pg_affected_rows($res)) {
				return $num;
			}
			else {
				return false;
			}
		}
		
	}
?>
Return current item: Access Data Object