如何仅使用 sql 语法(不使用 PHP)在 mysql table 中的 blob 中插入图像?
How to insert images in blob in mysql table using only sql syntax (without PHP)?
- 嗨,我是 SQL 的新手,我想将图像存储在 database.I 已经创建了一个具有 blob 数据类型的列,并尝试执行此处给出的以下语句
INSERT INTO `abc`
(`img`)
SELECT
BulkColumn FROM OPENROWSET(
Bulk 'C:\Users\adity\Desktop\New folder\a.png', SINGLE_BLOB) AS BLOB
给出错误
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
我也尝试了下面给出的代码 here
insert into table `abc`(`img`) values('C:\Users\name\Desktop\New folder\an.jpg') where id=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 插入 statement.I 我正在为我的数据库使用 wamp 服务器。
- 我知道我应该为图像使用文件系统而不是使用 database.But 文件系统实际上是什么 mean.Does 它意味着一个文件或图像托管站点,其地址将存储在数据库中。
我认为该命令是 MSSQL 语法。试试这个命令:
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/Users/adity/Desktop/New folder/a.png'))
此命令将图像存储为 BLOB
通过Mysql workbench,使用以下步骤将图像加载到数据库中非常容易。
- 右键单击 table 和 select "Load value from file" 中 (blob) 列的值。
- 然后我们可以提供系统中的图片路径。
- 然后自动转换成字节数组存储起来
- 最后保存修改table。
以下适合我,
但是,我能够通过先将图像 (fileName.jpg
) 文件移动到下面的文件夹(在我的例子中)来完成它 C:\ProgramData\MySQL\MySQL Server 5.7\Uploads
然后我执行下面的命令并且它有效对我来说,
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/an.jpg'));
希望对您有所帮助。
- 嗨,我是 SQL 的新手,我想将图像存储在 database.I 已经创建了一个具有 blob 数据类型的列,并尝试执行此处给出的以下语句
INSERT INTO `abc`
(`img`)
SELECT
BulkColumn FROM OPENROWSET(
Bulk 'C:\Users\adity\Desktop\New folder\a.png', SINGLE_BLOB) AS BLOB
给出错误
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
我也尝试了下面给出的代码 here
insert into table `abc`(`img`) values('C:\Users\name\Desktop\New folder\an.jpg') where id=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 插入 statement.I 我正在为我的数据库使用 wamp 服务器。
- 我知道我应该为图像使用文件系统而不是使用 database.But 文件系统实际上是什么 mean.Does 它意味着一个文件或图像托管站点,其地址将存储在数据库中。
我认为该命令是 MSSQL 语法。试试这个命令:
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/Users/adity/Desktop/New folder/a.png'))
此命令将图像存储为 BLOB
通过Mysql workbench,使用以下步骤将图像加载到数据库中非常容易。
- 右键单击 table 和 select "Load value from file" 中 (blob) 列的值。
- 然后我们可以提供系统中的图片路径。
- 然后自动转换成字节数组存储起来
- 最后保存修改table。
以下适合我,
但是,我能够通过先将图像 (fileName.jpg
) 文件移动到下面的文件夹(在我的例子中)来完成它 C:\ProgramData\MySQL\MySQL Server 5.7\Uploads
然后我执行下面的命令并且它有效对我来说,
INSERT INTO `abc`
(`img`)
VALUES
(LOAD_FILE('C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/an.jpg'));
希望对您有所帮助。