Subject RE: how to insert image blob in Firebird in PHP and ADODB
Author

i got it to work.


for now i am using PDO for Firebird, but it should be the same as ADODB. maybe.

i did it like this, if anyone want to know. i also have to create a field for the image type, so i can upload different types, and show them as the correct types.

i also had to set subtype to 0 in the image field.


 function savelogo_to_db($imgSrc,$dbh)

 {

    $img_src = $imgSrc;

    $imgbinary = fread(fopen($img_src, "r"), filesize($img_src));

    $img_str = base64_encode($imgbinary);

       try

       {

         $img_str = base64_encode($imgbinary);

         $sql="insert into logo (test) values('$img_str')";

         $result=run_sql($dbh,$sql);

       }

       catch (Exception $e)

       {

         echo "Failed: " . $e->getMessage();

       };

}



// and here is the function for retrieving image from the database, and show it.

function get_logo_blob_image($dbh)

{

   $sql="select test from logo";

   $result=db_fetch_rows($dbh,$sql);

     if ($result!==false)

     {

       $row = $result->fetch();

       $imgbinary=$row['TEST'];

       echo '<img src="data:image/png;base64,'.$imgbinary.'"/>';

     }

}


this is only a test i made for making it work. and it does.

it was hard to find any samples, so i just had to try on my own.