# either my $dbh = DBI->connect("dbi:mysql:dbname;mysql_server_prepare=1", "user","pass"); # or $dbh->{ mysql_server_prepare } = 1; #### export MYSQL_SERVER_PREPARE=1 #### my $query = qq{SELECT col1, col2, col3 FROM mytable LIMIT ? , ?}; my $sth = $dbh->prepare($query); my $lines = 20; for my $page_no (1..10) { $sth->execute($page_no, $lines); # do something with the page. } #### $dbh1->{ mysql_server_prepare } = 0; # emulated prepared statement $dbh2->{ mysql_server_prepare } = 1; # real prepared statement my $query = qq{select book_id from books where author_id = ? }; use DBI::Profile; $dbh1->{Profile} = DBI::Profile->new; $dbh2->{Profile} = DBI::Profile->new; $dbh1->{Profile} = 4; $dbh2->{Profile} = 4; my $sth1 = $dbh1->prepare($query); my $sth2 = $dbh2->prepare($query); timethese ( 5000, { emulated => sub { for (1 .. 15) { $sth1->execute($_); my $rows = $sth1->fetchall_arrayref(); } }, prepared => sub { for (1 .. 15) { $sth2->execute($_); my $rows = $sth2->fetchall_arrayref(); } } } ); print "emulated\n", $dbh1->{Profile}->format; print "prepared\n", $dbh2->{Profile}->format; $dbh1->{Profile} =0; $dbh2->{Profile} =0;