Aí está o meu código: imprimir.php <?
require_once(".\fpdf\fpdf.php");
include('conectar.php');
$v_query = "SELECT * FROM tabela";
$v_result = pg_query($dbconn, $v_query);
while($row = pg_fetch_object($v_result))
{
$campo1 = $row->campo1;
$campo2 = $row->campo2;
$campo3 = $row->campo3;
}
pg_free_result($v_result);
pg_close($dbconn);
class PDF extends FPDF
{
function Header()
{
$this->SetFont('Arial','BI',15);
$this->Cell(80);
$this->Cell(45,15,'LISTAGEM',0,0,'C');
$this->Ln(20);
}
function Footer()
{
$this->SetY(-15);
$this->SetFont('Arial','I',8);
$this->Cell(0,10,'Página '.$this->PageNo(),'0','0','L');
}
}
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('times','',12);
$pdf->SetX(10);
$pdf->Cell(0,8,'Cidade: ' . $campo1,0,0,'L');
$pdf->Ln();
$pdf->SetFont('times','',12);
$pdf->SetX(10);
$pdf->Cell(0,8,'Estado: ' . $campo2,0,0,'L');
$pdf->Ln();
$pdf->SetFont('times','',12);
$pdf->SetX(10);
$pdf->Cell(0,8,'País: ' . $campo3,0,0,'L');
$pdf->Ln(15);
$pdf->SetFont('Times','',12);
$pdf->Output("Relatorio.pdf", "I");
?>
conectar.php
<?
$dbconn = pg_connect("host=127.0.0.1 port=5432 dbname=banco user=postgres password=postgres") or die("Não foi possível conectar");
?> Se eu coloco a linha: $dbconn = pg_connect("host=127.0.0.1 port=5432 dbname=banco user=postgres password=postgres") or die("Não foi possível conectar"); dentro do arquivo imprimir.php dá certo. O que estou fazendo de errado?