How exactly are you expecting to use that script?
Normally when you fetch image data from a database, or pass an image file through PHP, then you do something along the lines of this in your HTML
-
<img src="fetchImage.php?id=1" alt="Image from PHP">
-
Which calls the PHP page
as an image to get the image data. The PHP script then fetches the image data from the database/file and passes it to the browser. - As far as the browser is concerned, there is absolutely no difference between calling a static JPEG image and calling a PHP script that returns JPEG image data.
Which brings me back to my original question: How are you going to be using a PHP script that returns data for multiple images? That would be no use in a normal <img> tag, as it would essentially just be read as a corrupted image.
If you want to build a page that displays all images stored in a MySQL table, you need to do that in two parts: The first part would create a list of <img> elements, one for each image, that queries a second PHP file with the ID of the image that <img> element is supposed to get. The second part would then be that PHP file, which would fetch that single image from the database and pass it's data back to the <img> tag.