표는 다음과 같습니다.
테이블 심볼 생성 (
SymbolID integer not null,
PngData BLOB
);
당신의 도움을 기대하십시오
여기 Perl로 할 수있는 방법이 있습니다. 먼저 PNG 이미지를 데이터베이스에로드 한 다음 파일로 추출하여 작동했음을 보여줍니다.
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $myfile = "picture.png";
my $dbname = "test.db";
my $data;
# Connect to database
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbname") || die "Cannot open db";
# >8 >8 >8 Cut starting here >8 >8 >8 >8 >8
# Open the image file
open MYFILE, $myfile or die "Cannot open file";
# Read in the file
while (<MYFILE>) {
$data .= $_;
}
close MYFILE;
# Insert image into database
my $sql = "INSERT INTO symbols VALUES (1,?)";
my $sth = $dbh->prepare($sql);
my $numrows = $sth->execute($data);
$sth->finish;
# >8 >8 >8 Cut ending here >8 >8 >8 >8 >8
#Now read it back and save as file
$sql = "SELECT PngData from symbols";
$sth = $dbh->prepare($sql);
$numrows = $sth->execute;
open OUTPUT, ">output.png";
my $ref = $sth->fetchrow_hashref;
my $newdata = $$ref{'PngData'};
print OUTPUT $newdata;
close OUTPUT;
$sth->finish;
$dbh->disconnect;
데이터베이스에서 이미지 BLOB를 추출하여 파일로 저장하려면 다음을 사용하십시오.
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $dbname = "test.db";
my ($sql,$sth,$numrows,$ref,$newdata);
# Connect to database
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbname") || die "Cannot open db";
# Read image and save as file
$sql = "SELECT PngData from symbols";
$sth = $dbh->prepare($sql);
$numrows = $sth->execute;
open OUTPUT, ">output.png";
$ref = $sth->fetchrow_hashref;
$newdata = $$ref{'PngData'};
print OUTPUT $newdata;
close OUTPUT;
$sth->finish;
$dbh->disconnect;
sqlite로 데이터베이스를 만들고이 코드를 가지고 놀려면 다음을 수행하십시오.
sqlite3 test.db "CREATE TABLE symbols(SymbolID integer,PngData BLOB);"
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다