简体   繁体   English

如何使用Perl将图像文件加载到SQLite中的Blob中?

[英]How can I load an image file into a blob in SQLite using Perl?

有人可以给我一个Perl示例,介绍如何在SQLite中将图像文件加载到Blob吗?

Well ... I wouldn't recommend storing images in any database (I prefer to store images in the filesystem and the paths to the image in the db) but ... that scenario is right in the documentation for DBD::SQLite 好吧...我不建议将图像存储在任何数据库中(我更喜欢将图像存储在文件系统中,并将图像的路径存储在数据库中),但是...这种情况在DBD :: SQLite文档中是正确的

use DBI qw(:sql_types);
my $dbh = DBI->connect("dbi:SQLite:dbfile","","");

my $blob = `cat foo.jpg`;
my $sth = $dbh->prepare("INSERT INTO mytable VALUES (1, ?)");
$sth->bind_param(1, $blob, SQL_BLOB);
$sth->execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM