Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:28:02+00:00 2026-06-07T02:28:02+00:00

I recently switched from MySQL to PostgreSQL. I have one problem left however. Previously,

  • 0

I recently switched from MySQL to PostgreSQL. I have one problem left however.

Previously, I would store small images in the BLOB format in MySQL.

PostgreSQL doesn’t know such thing as a BLOB.

I tried using BYTEA field type instead. This actually inserts an large (hexadecimal?) string I guess, but now I’m stuck trying to get this string back to displaying an actual image in PHP..

Any ideas? Thanks in advance.

Here is a piece of code I use to save the image in the database:

$data = bin2hex(file_get_contents('php://input'));

if (!empty($data)) {
  $sql = "UPDATE asset SET data = X'%s' WHERE uuid = '%s'";
  $args = array($data, $asset_uuid);
}

psql (9.1.3) and php 5.3.6 are used

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:28:04+00:00Added an answer on June 7, 2026 at 2:28 am

    Both answers posted here gave me some thoughts, but none were 100% of the answer.

    So, I will explain in this answer what I did to get it to work.

    When displaying the image, I used this:

    header('Content-Type: image/jpeg');
    
    $data = pack("H*", pg_unescape_bytea($data));
    
    echo $data;
    

    I’m running PHP 5.3.8, in PHP 5.4.0 it turns out you can use hex2bin instead of pack.

    When adding the image to the database, I used this:

    $data = pg_escape_bytea($data); // Escape input for PostgreSQL
    $sql  = "UPDATE asset SET data = '%s'WHERE uuid = '%s'";
    

    I’m glad it is working now. Thank you both Daniel and Johann!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently switched from a Java based project to a C#/.net project. I previously
I recently switched from using Linq to Sql to the Entity Framework. One of
We just recently switched from Visual Studio 2008 to Visual Studio 2010. I have
I recently switched from VB to C# and have, for the most part, been
I recently switched from ipython0.10 to ipython0.11. In ipython0.11, I only see a small
I've recently switched from WAMP/XAMPP to LAMP and one thing I found useful was
We have a WCF service that we recently switched from self-hosting to IIS-hosted. It
I have recently switched from Netbeans to Eclipse. I have a project which contains
We have a C# application written in C# and recently switched over from MbUnit
I've recently switched my assignment from Java to Scala. However, it still looks like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.