Affichage d'une image stockée dans un champ image d'une bdd sql server
Bonjour, je rencontre un problème pour afficher une imageà partir d'un champ image stockée dans une bdd sql server. J'ai essayé en utilisant un script mais il y a toujours un lien cassé. je sais qu'il est préférable de stocker plutôt le chemin mais je n'ai pas le choix dans ce cas de figure.
page-1
Code:
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
<?php
/*
Template Name: CA
*/
try {
$dbh = new PDO("odbc:Driver=$mssqldriver;Server=$hostname;dbname=$dbname;charset=french_ci_as", $username, $pw);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute (PDO::ATTR_ORACLE_NULLS, PDO::NULL_TO_STRING);
} catch (PDOException $exception) {
echo $exception->getMessage();
exit;
}
/?>
<div class="wrap">
<h1>Notre Conseil d'administration</h1>
<hr />
<?php
$retour = $dbh->prepare("SELECT COUNT(*) as nb_membre FROM [ID143953_b4c].[dbo].[SQL_PPH] P
JOIN [ID143953_b4c].[dbo].[SQL_TLP] I ON P.IDPPH = I.IDPPH
JOIN [ID143953_b4c].[dbo].[SQL_TIE] T ON T.IDTIE = I.IDTIE
WHERE P.FctOrg != '' AND P.Passif=0 AND I.Principal=1");
$retour->execute();
$membreparpage=30;
$dess = $retour->fetch(PDO::FETCH_ASSOC);
$totaldesmembre = $dess['nb_membre'];
$nombredepage = ceil($totaldesmembre/$membreparpage);
echo "<hr class='hr-left'/><div class='pagi'>";
if (isset($_GET['pagination']) && is_numeric($_GET['pagination']) && $_GET['pagination'] > 0 && $_GET['pagination'] <= $nombredepage)
{
$page = intval($_GET['pagination']);
}
else
{
$page = 1;
}
if ($page > 1):
?><a href="?pagination=<?php echo $page - 1; ?>"><span class="dashicons dashicons-arrow-left-alt2"></span></a> <?php
endif;
for ($i = 1 ; $i <= $nombredepage ; $i++)
{
if($i==$page){
$class="active";
}else{
$class="inactive";
}
echo '<a href="?pagination=' . $i . '"class='.$class.'>' . $i . '</a> ';
}
if ($page < $nombredepage):
?><a href="?pagination=<?php echo $page + 1; ?>"><span class="dashicons dashicons-arrow-right-alt2"></span></a><?php
endif;
echo "</div><hr class='hr-right'/>";
$premieremembreafficher = $page* $membreparpage - $membreparpage;
$reponse=$dbh->prepare("SELECT P.IDPPH,P.nom,P.Pre,P.Passif,T.IDTIE,T.Libelle,T.Secteur,P.FctEnt,P.Photo_BInaire,P.FctOrg,P.NumAdmin FROM [ID143953_b4c].[dbo].[SQL_PPH] P
JOIN [ID143953_b4c].[dbo].[SQL_TLP] I ON P.IDPPH = I.IDPPH
JOIN [ID143953_b4c].[dbo].[SQL_TIE] T ON T.IDTIE = I.IDTIE
WHERE P.FctOrg != '' AND P.Passif=0 AND I.Principal=1 ORDER BY P.NumAdmin ASC
");
$reponse->execute();
while ($donnees = $reponse->fetch()) {
$id=$donnees['IDPPH'];
?><div class='membres entreprises'>
<?php echo '<img src="image.php?id='.$id.'" class="img-membre"/>';?>
<h3 class='nom'><?php echo utf8_encode($donnees['Pre']); ?> <?php echo utf8_encode($donnees['nom']); ?> </h3>
<p class='fct membre'><?php echo utf8_encode($donnees['FctOrg']); ?> </p>
<p class='ent membre'><strong>Entreprise: </strong><?php echo utf8_encode($donnees['Libelle']); ?></p>
</div><?php
}
$reponse->closeCursor();
?>
</div> |
image.php
Code:
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
|
<?php
try {
$dbh = new PDO("odbc:Driver=$mssqldriver;Server=$hostname;dbname=$dbname;", $username, $pw);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_TO_STRING);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_TO_STRING);
$reponse = $dbh->prepare('SELECT P.Photo_BInaire FROM [ID143953_b4c].[dbo].[SQL_PPH] P
WHERE P.IDPPH=:id AND P.IdLibType IN(1,2,3,12)');
$reponse->bindValue('id', $_GET['id'], PDO::PARAM_INT);
$reponse->execute();
$donnees = $reponse->fetch();
} catch (EXCEPTION $e) {
die('Erreur : ' . $e->getMessage());
exit();
}
header('Content-Type: image/jpg');
echo $donnees['Photo_BInaire'];
?> |
POuvez-vous m'aider svp