本示例输出两次“blob”。我怎么能发现,如果列的数据类型是TEXT
?DBI/DBD :: mysql/mysql_type_name:如何区分Blob和Text?
#!/usr/bin/env perl
use warnings;
use strict;
use DBI;
use Data::Dumper;
my$dbh = DBI->connect("DBI:mysql:dbname=test", 'user', 'passwd', {
RaiseError => 1,
AutoCommit => 1,
}) or die DBI->errstr;
my $table = 'my_test_table';
$dbh->do("DROP TABLE IF EXISTS $table");
$dbh->do("CREATE TABLE $table (Foo TEXT, Bar BLOB)");
my $sth = $dbh->prepare("INSERT INTO $table (Foo, Bar) VALUES(?, ?)");
$sth->execute('a', 'a');
$sth = $dbh->prepare("SELECT * FROM $table");
$sth->execute();
my $col_types = $sth->{mysql_type_name};
print Dumper $col_types;
输出:
$VAR1 = [
'blob',
'blob'
];