How to read a blob in Base64 using PHP and MySQL?
<p>I am a newb with 6 months experience, self-taught via StackEx/books/etc.  Created a pretty decent website with login/register and storing some info via mySQL.  I have been through every single BLOB post here and I have some decent output.</p>

<p>I think I, like most newbs, know enough to be dangerous, don't have the greatest foundation laid out so when it gets to serious understanding of built-in functions, arrays and passing arguments we can lose the flow and I basically think I have dug a hole by using includes to call some navbar so that I can't just use a header to output the damn image as I echo the user name after login so it has already outputted lines and it will be a monster to undo.  Three levels of nav, unauthenticated, authenticated and admin.</p>

<p>The database connection and write to/read from is OK.  I can store the BLOB and I can even read it back and store the array in a variable and then debug see the binary but I can't get it to display on an HTML page.</p>

<p>Here is the fun:</p>

<pre><code>$stmt = $dbc2-&gt;query("SELECT * FROM equip1");

while ($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC))
{
$name = $row['equipname1'];
$desc = $row['equipdesc1'];
$img = $row['equipimg1'];
}

&lt;div class="col-lg-12"&gt;
    &lt;h1&gt;&lt;?php echo $name ?&gt;&lt;/h1&gt;
    &lt;p&gt;&lt;?php echo $desc ?&gt;&lt;/p&gt;
    &lt;pre&gt;
        &lt;?php print_r($img); ?&gt;
    &lt;/pre&gt;
    &lt;?php echo "&lt;img src='data:image/jpeg;base64," . base64_encode( $img ) . "' /&gt;"; ?&gt;
&lt;/div&gt;
</code></pre>

<p>$dbc2 connects
equip1 table is two simple varchar cols, one BLOB col.
$name and $desc echo out ok, the $img displays broken link.
I check the array via pre code and is matching, per what is stored in dB during upload.
From what I have read and gone through, seems like you can't do this at same time unless via data URI which I have done but still broken link.  Not making sense to me at all.  I try the header and of course output already started but I can see also outputs the binary.</p>

<p>Here is screenshot of the URI method:</p>

<p><img src="https://i.stack.imgur.com/sCCFM.jpg" alt="binary"></p>

<p>Since both methods "seem" to get into and out of the dB but do not display I'm going round in circles.  Please help me out to display the image on an html page. I would like to echo it anywhere and then I can just style the page after that.  Thanks!</p>