Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

database - How to insert images in blob in mysql table using only sql syntax (without PHP)?

  1. Hi,I am new to SQL and I wanted to store images in the database.I already created a column with blob data type and tried to execute the following statement as given here
INSERT INTO `abc`
    (`img`)
    SELECT  
        BulkColumn FROM OPENROWSET(
            Bulk 'C:UsersadityDesktopNew foldera.png', SINGLE_BLOB) AS BLOB

which gives error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( Bulk C:Users ameDesktopNew foldera.png, SINGLE_BLOB) AS BLOB' at line 4

I also tried following code as given here

insert into table `abc`(`img`) values('C:Users
ameDesktopNew folderan.jpg') where id=1;

which gives the error

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table abc(img) values('C:UsersadityDesktopNew folderan.jpg') where id=1' at line 1

So please suggest me how to store images in a blob without using php,etc and simply using simple sql insert statement.I am using wamp server for my database.

  1. I know that I should use file system for images instead of using database.But what does a file system actually mean.Does it mean a file or image hosting site whose address will be stored in database.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think that command is a MSSQL syntax. Try this command:

INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/Users/adity/Desktop/New folder/a.png'))

This command stores image as a BLOB


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...