SQLite Forum

Timeline
Login

6 forum posts by user DMVB123

2021-03-12
23:00 Reply: Inserting the image as BLOB (artifact: aa43ec6a76 user: DMVB123)

Hello,

What programming language are you using?

I have a very similar question, only I need the coding to be done with PHP..

I found (3) techniques that I have been advised with.

First, is to SAVE the image to an "images" folder and only store the filename and file path in your database.

Second is to ENCODE the image using "base64_encode()" and save the DATA as a text field, then DECODE that DATA and using base64_decode() and save it as an image file.

The third option is the one I think you are most interested in and I am still trying to sort out how to save an image file to an SQLITE database BLOB field using PHP.

Check this article: https://makitweb.com/upload-and-store-an-image-in-the-database-with-php/

If you have an answer, feel free to share..

I hope my response was helpful..

2021-03-11
21:51 Reply: How to READ and WRITE an image to an SQLITE BLOB FIELD (artifact: 14217b4f34 user: DMVB123)

Hi Tim,

Thank you for the reply..

Here is all I have right now, I planned on passing the ROW ID and Field name via a URL as shown.

<?php

// URL Format: // http://www.localhost/sqlite/ccc_update_image.php?iduser=1&idimage=image1

$userid = $_GET['iduser']; $imageid = $_GET['idimage'];

class MyDB extends SQLite3 { function __construct() { $this->open('ccc_contents.db'); } }

$db = new MyDB(); if(!$db){ echo $db->lastErrorMsg(); } else { echo "Opened database successfullyn"; }

///////////////////////////////////////////////////////////////////////////////

// Need PHP code to READ and WRITE to external image file and SAVE to SQLITE

///////////////////////////////////////////////////////////////////////////////

$ret = $db->exec($sql); if(!$ret) { echo $db->lastErrorMsg(); } else { echo "Records created successfullyn"; } $db->close(); ?>

21:34 Reply: How to READ and WRITE an image to an SQLITE BLOB FIELD (artifact: 69b8c4e9f8 user: DMVB123)

Hi Ryan,

Thank you for the reply..

I am trying to find "how" to read and write an image file to an SQLITE database using PHP..

This is the starting point for me since I have never done that before.

I have working PHP code that works great with my existing SQLITE database and I now need to be able to read and write images to my SQLITE database, however, I am having trouble finding a working reference example, sample code, or tutorials that can guide me.

Do you know of any example code, sample code, or tutorials that can help me learn what I need to know to get this working?

21:26 Reply: How to READ and WRITE an image to an SQLITE BLOB FIELD (artifact: 75ec5e9d79 user: DMVB123)

Hi Keith,

Thank you for the reply..

I am trying to find "how" to read and write an image file and save it to an SQLITE database using PHP..

This is the starting point for me since I have never done that before.

I have working PHP code that works great and I now need to be able to read and write images to my SQLITE database, however, I am having trouble finding a working reference example, sample code, or tutorials that can guide me.

Do you know of any example code, sample code, or tutorials that can help me learn what I need to know to get this working?

21:12 Reply: How to READ and WRITE an image to an SQLITE BLOB FIELD (artifact: 6b6c4b7582 user: DMVB123)

Thank you for the help Kees..

Do you know of any PHP sample code, examples, or tutorials that might help me get this working?

20:22 Post: How to READ and WRITE an image to an SQLITE BLOB FIELD (artifact: 61852533e8 user: DMVB123)

I have an existing web application that uses an SQLITE database and PHP coding which works GREAT !!!

I now need to SAVE images to my SQLITE database. I added a BLOB field type and I am able to easily SAVE and EXPORT an image file using the DB Browser application.

I found the following reference on the "sqlite.org" website which explains how to READ and WRITE an image file to an SQLITE database, however, I am having trouble getting it to work.

Click here for the link: Reference Material https://www.sqlite.org/cli.html#fileio

Mostly confused by the terminology in the following: "name TEXT" "type TEXT" "img BLOB"

sqlite> INSERT INTO images(name,type,img) ...> VALUES('icon','jpeg',readfile('icon.jpg'));

Creates TABLE: sqlite> CREATE TABLE images(name TEXT, type TEXT, img BLOB);

INSERTS JPEG image from an external file into an SQLITE database. sqlite> INSERT INTO images(name,type,img) ...> VALUES('icon','jpeg',readfile('icon.jpg'));

EXPORTS an image from an SQLITE database sqlite> SELECT writefile('icon.jpg',img) FROM images WHERE name='icon';

I would appreciate any help I can get in coding this using PHP..