0

Here, i'm trying to fetch the image from database. In my database i can see a image file size ([BLOB - 62.3 KiB]). But, it didn't work. i didn't get any error here. i'm confused where i made a mistake here?

<?php
    include('config.php');

    ini_set('display_errors', '1');
    error_reporting(E_ALL);

    try
    {
        $stmt = $conn->prepare('SELECT * FROM ebusers');
        $conn->errorInfo();
        $stmt->execute();
        while($row = $stmt->fetch(PDO::FETCH_ASSOC)) 
        {   
            echo '<img class=shadow_img width=160 height=180 src="data:image/png;base64,' . base64_encode($row['UserProfilePicture']) . '"/>';
            echo $row['Address'];
            echo "<br>";echo "<br>";echo "<br>";echo "<br>";
        }
    }
    catch(PDOException $e)
    {
        'Error : '.$e->getMesssage();
    }
?>
2
Contributors
3
Replies
20
Views
3 Years
Discussion Span
Last Post by AmirHosseinHP
1

Quote from here:
Remember that you can't retreive BLOB data using something like this :

<?php
$sql = 'SELECT * FROM sometable LIMIT 1';
$stmt = $dbh->prepare($sql);
$stmt->execute();
$stmt->setAttribute(PDO::FETCH_ASSOC);
$row = $stmt->fetch();

$myFile = $row['file'];
?>

Instead of this you should try following approach:

<?php
$sql = "SELECT mime, file FROM sometable LIMIT 1"; 
$stmt = $dbh->prepare($sql); 
$stmt->execute(); 

$stmt->bindColumn(1, $mime,); 
$stmt->bindColumn(2, $file, PDO::PARAM_LOB); 

$stmt->fetch(); 

header('Content-type: '.$mime);
print $file; 
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.