此示例输出两次“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'
];