Código PHP:
<?php
class connex
{
private $user;
private $clave;
private $servidor;
private $db;
private $port;
private $conex;
function __construct()
{
$this->user = 'root';
$this->clave='';
$this->servidor = 'localhost';
$this->db = 'basedatos';
$this->port = 5432;
$this->conex='';
}
public function conectar()
{
$this->conex = pg_connect("host=".$this->servidor." port=".$this->port."password=".$this->clave." user=".$this->user." dbname=".$this->db." ") or die("ERROR DE CONEXION");
return $this->conex;
}
public function consulta($pConsulta)
{
$query = pg_query($this->conex,$pConsulta);
return $query;
}
public function row($pConsulta)
{
$row = pg_fetch_array($pconsulta,0);
return $row;
}
}
?>
y esta son las consultas
Código PHP:
require_once("connex/connex.php");
$conexion = new connex();
$consulta = $conexion->consulta("select * from tabla");
while($row = $conexion->row($consulta))
{
echo $row['ciucod']."<br>";
}