1

为什么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
4

1 回答 1

1

该参数mysql_bind_type_guessing试图猜测您的输入数据是否为数字。如果数据是数字,它不会引用它。

似乎对数字性的不充分检查导致它认为这e是一个数字(e可以是数字的一部分,例如1.2e-3)。

因为它没有被引用,所以 MySql 尝试将e其视为列名,因此出现错误。

如果我的猜测是正确的,我会认为它是DBD::MySQL.

更新: 确实,这是一个错误

于 2013-02-11T13:25:14.177 回答