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

发布于 2024-07-24 04:43:11 字数 54 浏览 3 评论 0原文

有人能给我一个关于如何将图像文件加载到 SQLite 中的 blob 中的 Perl 示例吗?

Could someone please give me a Perl example on how to load an image file into a blob in SQLite?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罗罗贝儿 2024-07-31 04:43:11

嗯...我不建议将图像存储在任何数据库中(我更喜欢将图像存储在文件系统中并将图像的路径存储在数据库中)但是...该场景在 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();

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文