Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / share / doc / libdbd-mysql-perl / examples / | server ip : 172.67.156.115 your ip : 172.70.80.63 H O M E |
Filename | /usr/share/doc/libdbd-mysql-perl/examples/bug30033.pl |
Size | 868 |
Permission | rwxr-xr-x |
Owner | root : root |
Create time | 27-Apr-2025 10:10 |
Last modified | 18-Oct-2013 03:23 |
Last accessed | 07-Jul-2025 02:16 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
use DBI;
our $opt_prepared;
GetOptions (
"p|prepared" => \$opt_prepared
);
my $dsn = "DBI:mysql:database=test;host=localhost";
$dsn .= ";mysql_server_prepare=1" if $opt_prepared;
my $dbh = DBI->connect( $dsn, 'root', '', { RaiseError => 1 } )
or die $DBI::errstr;
unlink('./bug3033.trace.log');
$dbh->trace(4, './bug3033_trace.log');
$dbh->do('DROP TABLE IF EXISTS buggy');
$dbh->do('CREATE TABLE buggy ( id int(3) )');
$dbh->do('INSERT INTO buggy (id) VALUES (1)');
my $query= "SELECT id FROM
-- It's a bug
buggy WHERE id = ?";
print "with var:\n";
my $ref= $dbh->selectall_arrayref($query, {}, 1);
print Dumper $ref;
print "with string terminator:\n";
$ref= $dbh->selectall_arrayref(<<END, {}, 1);
SELECT id
FROM buggy
-- It's a bug!
WHERE id = ?
END
print Dumper $ref;
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
use DBI;
our $opt_prepared;
GetOptions (
"p|prepared" => \$opt_prepared
);
my $dsn = "DBI:mysql:database=test;host=localhost";
$dsn .= ";mysql_server_prepare=1" if $opt_prepared;
my $dbh = DBI->connect( $dsn, 'root', '', { RaiseError => 1 } )
or die $DBI::errstr;
unlink('./bug3033.trace.log');
$dbh->trace(4, './bug3033_trace.log');
$dbh->do('DROP TABLE IF EXISTS buggy');
$dbh->do('CREATE TABLE buggy ( id int(3) )');
$dbh->do('INSERT INTO buggy (id) VALUES (1)');
my $query= "SELECT id FROM
-- It's a bug
buggy WHERE id = ?";
print "with var:\n";
my $ref= $dbh->selectall_arrayref($query, {}, 1);
print Dumper $ref;
print "with string terminator:\n";
$ref= $dbh->selectall_arrayref(<<END, {}, 1);
SELECT id
FROM buggy
-- It's a bug!
WHERE id = ?
END
print Dumper $ref;