我试图使用perl 将二进制文件(JPG图像)插入MySQL数据库
表:
CREATE TABLE `images` (
`sku` CHAR(12) NOT NULL,
`index` TINYINT(1) UNSIGNED NOT NULL,
`main` BLOB NULL
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
ROW_FORMAT=DYNAMIC
;
Run Code Online (Sandbox Code Playgroud)
Perl的:
$dbh_local = DBI->connect("DBI:mysql:database=db;host=127.0.0.1;mysql_enable_utf8=1", "XXX", "XXX", {'RaiseError' => 1, 'mysql_auto_reconnect' => 1});
open IMAGE, "c:/image.jpg" or die $!;
while(read IMAGE, $buff, 1024) {
$image .= $buff;
}
close(IMAGE);
my $sku = 'VM1000032999';
my $index = 1;
$query = "INSERT INTO images (sku,index,main) values (?,?,?)";
$sth = $dbh_local->prepare($query);
$sth->bind_param(1,$sku);
$sth->bind_param(2,$index);
$sth->bind_param(3,$image, DBI::SQL_BLOB);
$sth->execute();
$sth->finish();
Run Code Online (Sandbox Code Playgroud)
但是我收到此错误: …