为什么mysql_bind_type_guessing
启用时会出现此错误,为什么仅使用参数“e”而不使用参数“a”?
#!/usr/bin/env perl
use warnings;
use strict;
use 5.10.1;
use utf8;
use open qw(:utf8 :std);
use DBI;
my $user = '...';
my $passwd = '...';
my $dbh = DBI->connect( "DBI:mysql:dbname=information_schema", $user, $passwd, {
PrintError => 0,
RaiseError => 1,
} ) or die DBI->errstr;
my $db = 'my_test_db';
$dbh->do( "DROP DATABASE IF EXISTS $db" );
$dbh->do( "CREATE DATABASE $db" );
$dbh = DBI->connect( "DBI:mysql:dbname=$db", $user, $passwd, {
PrintError => 0,
RaiseError => 1,
AutoCommit => 1,
mysql_enable_utf8 => 1,
mysql_bind_type_guessing => 1,
} ) or die DBI->errstr;
my $table = 'Abteilung';
$dbh->do( "CREATE TABLE IF NOT EXISTS $table (
AbtNr INT NOT NULL,
Name VARCHAR(30),
PRIMARY KEY(AbtNr)
)" );
my $sth = $dbh->prepare( "INSERT INTO $table ( AbtNr, Name ) VALUES ( ?, ? )" );
my $abteilung_values = [
[ 1, 'EDV' ],
[ 2, 'Verwaltung' ],
[ 3, 'Chefetage' ],
];
for my $row ( @$abteilung_values ) {
$sth->execute( @$row );
}
$sth = $dbh->prepare( "SELECT * FROM $table WHERE name REGEXP ?" );
$sth->execute( 'e' );
while ( my $row = $sth->fetchrow_arrayref() ) {
say "@$row";
}
mysql_bind_type_guessing enabled
execute argument 'e':
# DBD::mysql::st execute failed: Unknown column 'e' in 'where clause' at ./perl3.pl line 46.
execute argument 'a':
# 2 Verwaltung
# 3 Chefetage
mysql_bind_type_guessing disabled
execute argument 'e':
# 1 EDV
# 2 Verwaltung
# 3 Chefetage
execute argument 'a':
# 2 Verwaltung
# 3 Chefetage