Displaying multiple Images, BLOB data, from a MySQL database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
back_up
Forum Newbie
Posts: 2
Joined: Sun Dec 13, 2009 11:18 am

Displaying multiple Images, BLOB data, from a MySQL database

Post by back_up »

Need to display multiple images stored as BLOB data types in a MySQL table. Using a while loop, other fields in the same table with text data type, displays in a browser showing all rows when the BLOB field is not included.

The BLOB data (the images), often are displayed as binary data but needs to show as actual images.

Apparently there is an issue with PHP with displaying the binary data stored in a variable directly as an image when echoing or printing the variable with BLOB data using echo $TheBlobData; or print $TheBlobData;.

In some instances, the query executes, retrieves all rows but only displays an image, instead of all the images per row.

Storing the images in directories has security issues, other risk and the BLOB data needs to be stored and pulled directly from the database.


--------------------
Field Name, DataType
---------------------
ID, int
Picture, BLOB
Type, VARCHAR

For example this prints the ID of each row:
while ($rows = mysql_fetch_object($result))
{
echo $rows->ID;
}
and this prints the image Type stored in a field of each row

while ($rows = mysql_fetch_object($result))
{
echo $rows->Type;
}

but this prints each row of the images as binary data but needs to print actual images:

while ($rows = mysql_fetch_object($result))
{
echo $rows->Picture;
}

When inserting the header() function to describe the image data type, it only prints an image using the same while loop, in some cases it simply shows a blank page and echos the address of the page:

while ($rows = mysql_fetch_object($result))
{
header ();
echo $rows->Picture;
}

This requires printing the multiple BLOB data directly as images to a page for each row in a table and not just an image on the page. For users of Postgres SQL, is this also an issue and are they open source databases where BLOB data types can be displayed directly as images by echoing or printing the BLOB data variable?

Should you intend to respond, read carefully and ensure postings are pertinent.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Displaying multiple Images, BLOB data, from a MySQL database

Post by AbraCadaver »

This is an exact duplicate of: viewtopic.php?f=1&t=110171&p=582713#p582713

I answered your question, and instead of replying with more questions or clarifications, you began harassing me via private messages stating that I shouldn't have replied because it was not "exactly" what you wanted. You also refuse to follow the forum rules as you have not used any code tags. :crazy:

If you would liked to be shunned and ignored by the helpful people in this community that are far better at PHP/software development than you, you're on the right track.

Surprisingly, since I'm a nice guy and my skillz are far superior to yours, I am still willing to help. :) So long as you recognize that what you are doing is not possible and what I have posted is about the only way to do it, we can probably come to a solution for you.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply