It is not clear what you're trying to do.
If you are storing image data in MySQL and wish to serve it, then you should write a separate image script that starts out by calling the function header("Content-type: image/gif") or header("Content-type: image/jpeg") to set its mime type.
In that case, the banner rotator script would generate a tag like this:
img src="/path/to/imagescript.php?id=somevalue"
Ordinarily, though, a banner rotator would not store image data in the database, but rather store metadata only and leave the ad banners in the filesystem.
In that case the banner script would generate a normal reference like this, pulling the filename from the database:
img src="/path/to/banner.jpg"