1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| <?php
$pdf = new phpToPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
try {
// $bdd est une base de données est différent de $pdo qui est une connexion
$pdo = new PDO('pgsql:host=localhost;dbname=db', 'user', 'pass');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
}
catch(Exception $e) {
die('Erreur : ' . $e->getMessage());
}
// pg_escape_string ne sert à rien car il faut utiliser pg_connect et non PDO
// PDO te permet de sécuriser tes données alors pourquoi s'en priver ?
// $categorie = pg_escape_string($_POST['categorie']);
$sql = "SELECT * FROM table WHERE categorie1 = :categorie ORDER BY nom_rep";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':categorie', $_POST['categorie'], PDO::PARAM_STR);
$exec = $stmt->execute();
if ($exec) {
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
else {
die(print_r($stmt->errorInfo()));
}
// Définition des propriétés du tableau.
$proprietesTableau = array(
'TB_ALIGN' => 'L',
'L_MARGIN' => 15,
'BRD_COLOR' => array(0,92,177),
'BRD_SIZE' => '0.3'
);
$proprieteContenu = array(
'T_COLOR' => array(0,0,0),
'T_SIZE' => 10,
'T_FONT' => 'Arial',
'T_ALIGN_COL0' => 'L',
'T_ALIGN' => 'R',
'V_ALIGN' => 'M',
'T_TYPE' => '',
'LN_SIZE' => 6,
'BG_COLOR_COL0' => array(245, 245, 150),
'BG_COLOR' => array(255,255,255),
'BRD_COLOR' => array(0,92,177),
'BRD_SIZE' => 0.1,
'BRD_TYPE' => '1',
'BRD_TYPE_NEW_PAGE' => ''
);
foreach($data as $row) {
$tableau[] = array(
utf8_decode($row['nom_rep']),
utf8_decode($row['prenom_rep']),
utf8_decode($row['tel1'])
);
}
$pdf->drawTableau($pdf, $proprietesTableau, $proprieteContenu, $tableau );
$pdf->output();
?> |
Partager