Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DBD::MySQL:我该如何处理;“LongReadLen”;对功能的影响?_Mysql_Perl_Dbi_Truncate - Fatal编程技术网

DBD::MySQL:我该如何处理;“LongReadLen”;对功能的影响?

DBD::MySQL:我该如何处理;“LongReadLen”;对功能的影响?,mysql,perl,dbi,truncate,Mysql,Perl,Dbi,Truncate,如何更改此脚本以截断BLOB输出 #!/usr/bin/env perl use warnings; use strict; use utf8; use 5.10.1; use DBI; my $user = 'username'; my $passwd = 'password'; my $db = 'information_schema'; my $dbh = DBI->connect( "DBI:mysql:dbname=$db", $user, $passwd, { Ra

如何更改此脚本以截断BLOB输出

#!/usr/bin/env perl
use warnings;
use strict;
use utf8;
use 5.10.1;
use DBI;

my $user = 'username';
my $passwd = 'password';

my $db = 'information_schema';
my $dbh = DBI->connect( "DBI:mysql:dbname=$db", $user, $passwd, {
    RaiseError => 1,
    AutoCommit => 1,
} ) or die DBI->errstr;

$db = 'test_truncate';
$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,
} ) or die DBI->errstr;

$dbh->{LongReadLen} = 5;
$dbh->{LongTruncOk} = 1;

my $table = 'table_truncate';
$dbh->do( "CREATE TABLE IF NOT EXISTS $table ( Id INT, my_Blob BLOB )" );
my $sth = $dbh->prepare( "INSERT INTO $table ( Id, my_Blob ) VALUES ( ?, ? )" );

my $blob = '123456789' x 20;
$sth->execute( 1, $blob );

$sth = $dbh->prepare( "SELECT * FROM $table" );
$sth->execute();
while ( my $row = $sth->fetchrow_arrayref() ) {
    say for @$row;
}
产出:

1
123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789

像这样调整输出

while ( my $row = $sth->fetchrow_arrayref() ) {
    print substr($_,0,78)."\n" for @$row;
}

你的意思是我可以使用
substr
而不是
LongReadLen
LongRuncok
?LongReadLen将限制fetchfow从数据库读取的字节数。substr限制显示的字节数。它们在不同的地点运作。在向用户显示数据的最终位置使用substr会限制用户看到的内容。使用substr不会限制数据库服务器和客户端程序之间的数据量。LongReadLen限制了从数据库服务器流向客户机程序的数据量。嗯,要么错误是显而易见的,要么这里涉及到一些秘密知识。