Search notes:

Perl module DBI::st

Apparently, DBI::st is the class for statement handles in DBI.

fetchall_arrayref

#!/usr/bin/perl
use warnings;
use strict;

use DBI;

unlink 'the.db' if -e 'the.db';
my $dbh = DBI->connect('dbi:SQLite:dbname=the.db') or die "Could not create the.db";

$dbh -> do('create table tab (
  id    integer,
  col1  text,
  col2  text
)');

my $sth = $dbh -> prepare('insert into tab values (?, ?, ?)');
$sth -> execute(1, 'foo', 'one'  );
$sth -> execute(2, 'bar', 'two'  );
$sth -> execute(3, 'baz', 'three');

$sth = $dbh->prepare('select col1, col2 from tab where id > ?');
$sth -> execute(1);


#
#   fetchall_arrayref returns a reference to an array:
#   
    my $res = $sth->fetchall_arrayref;
    print '$res = ', ref $res, "\n";

#
#   Iterating over the returned reference's items (the records).
#
for my $rec (@{$res}) {
#
#   The recordes are stored in array references as well:
#
    print '$rec = ', ref $rec, "\n";

#
#   Print the selected values:
#
    printf "    %s %s\n", @{$rec};
}
Github repository PerlModules, path: /DBI/st/fetchall_arrayref.pl

See also

Perl modules

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759398080, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/modules/DBI/st/index(86): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78