如何仅使用sql语法(不使用PHP)在mysql表的blob中插入图片? [英] How to insert images in blob in mysql table using only sql syntax (without PHP)?
问题描述
- 我是SQL的新手,我想将图像存储在数据库中.我已经创建了一个具有blob数据类型的列,并尝试执行此处给出的以下语句
INSERT INTO `abc`
(`img`)
SELECT
BulkColumn FROM OPENROWSET(
Bulk 'C:\Users\adity\Desktop\New folder\a.png', SINGLE_BLOB) AS BLOB
出现错误
您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以获取在'( 批量
C:\Users\name\Desktop\New folder\a.png
,SINGLE_BLOB)为BLOB',位于第4行
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\name\Desktop\New folder\a.png
, SINGLE_BLOB) AS BLOB' at line 4
我还在此处
insert into table `abc`(`img`) values('C:\Users\name\Desktop\New folder\an.jpg') where id=1;
出现错误
#1064-您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在'table
abc
(img
)values('C:\ Users \ adity \ Desktop \ New folder \ an.jpg')附近使用,其中id = 1'在第1行
#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:\Users\adity\Desktop\New folder\an.jpg') where id=1' at line 1
所以请建议我如何在不使用php等文件的情况下将图像存储在blob中,而仅使用简单的sql插入语句.我正在为数据库使用wamp服务器.
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.
- 我知道我应该使用文件系统而不是数据库来存储图像,但是文件系统的实际含义是什么呢?这意味着文件或图像托管站点的地址将存储在数据库中.
推荐答案
我认为该命令是MSSQL语法.尝试以下命令:
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'))
此命令将图像存储为BLOB
This command stores image as a BLOB
这篇关于如何仅使用sql语法(不使用PHP)在mysql表的blob中插入图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!