KMA
KMA

Reputation: 211

Insert image to a SQL database

I have used to bellow SQL query to create the 'Images' table where I want to store the images and other details.

CREATE TABLE Images (
        picid int NOT NULL AUTO_INCREMENT,
        description VARCHAR(40),
        image BLOB,
        PRIMARY KEY (picid));

Then I used DML as below

INSERT INTO Images VALUES (NULL,'picture of a dog','D:\Images\one.jpg');

Queries are executed with out any error. But field viewer of image column does not contain the image. It gives the following for binary. enter image description here

How can I solve my problem ?

Upvotes: 0

Views: 873

Answers (2)

loyCossou
loyCossou

Reputation: 19

INSERT INTO Images VALUES (NULL,'picture of a dog','D:\Images\one.jpg');

This means you are storing the string 'D:\Images\one.jpg' in the database.

Follow this link for details on how to proceed: http://www.techcubetalk.com/tutorial-on-how-to-store-images-in-mysql-blob-field/

Cheers

Upvotes: 0

user188654
user188654

Reputation:

You need to use LOAD_FILE for that.

INSERT INTO Images VALUES (NULL,'picture of a dog', LOAD_FILE('D:\Images\one.jpg'));

If you don't MySQL will treat your image value just as a string and store it accordingly into the blob field.

Upvotes: 2

Related Questions