即使ChopBlanks未啟用,為什么從列值中洗掉尾隨空格?
use DBI;
my $value = ' string ';
my $db = 'my_mysql_db';
my $dbh = DBI->connect( "dbi:mysql:db=$db", 'user', '*', { RaiseError => 1, ChopBlanks => 0 } ) or die DBI->errstr;
my $table = 'test_mysql';
$dbh->do( "CREATE TABLE IF NOT EXISTS $table (col_1 CHAR(64))" );
my $sth = $dbh->prepare( "DELETE FROM $table WHERE col_1 = ?" );
$sth->execute( $value );
$sth = $dbh->prepare( "INSERT INTO $table (col_1) VALUES( ? )" );
$sth->execute( $value );
$sth = $dbh->prepare( "SELECT * FROM $table" );
$sth->execute();
$sth->dump_results;
' string'
1 rows
uj5u.com熱心網友回復:
我相信這是 MySQL 的事情,而不是 DBI 的事情。從11.3.2 開始,CHAR 和 VARCHAR 型別:
存盤值時
CHAR,它們會用空格填充到指定長度。PAD_CHAR_TO_FULL_LENGTH檢索 CHAR 值時,除非啟用 SQL 模式,否則將洗掉尾隨空格。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/498063.html
