phppostgresqldata-uribytea

How to convert the PostgreSQL bytea value into Data URL value using PHP


PostgreSQL has this datatype called bytea. It is their version of a blob.

In displaying images, png/jpg/gif, the current trend nowadays is to use Data URLs.

My question is how to convert a bytea value into a Base64 Data URL value?

References


Solution

  • You may also fetch the complete image data URL from your database, e.g.:

    SELECT 'data:image/gif;base64,' || encode(image_data, 'base64') AS image_url 
    FROM ...