Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # examples/sqlite_in_memory.pl
- use strict;
- use warnings;
- use Data::Dumper qw(Dumper);
- use DBI;
- my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:");
- $dbh->do("CREATE TABLE words (
- id INTEGER PRIMARY KEY,
- word VARCHAR(255)
- )");
- for my $word ("abc", "def", "ghi") {
- $dbh->do("INSERT INTO words (word) VALUES (?)", undef, $word);
- }
- my $sth = $dbh->prepare("SELECT * from words");
- $sth->execute;
- while (my $h = $sth->fetchrow_hashref) {
- print Dumper $h;
- }
- __END__
- Output:
- $VAR1 = {
- 'id' => 1,
- 'word' => 'abc'
- };
- $VAR1 = {
- 'id' => 2,
- 'word' => 'def'
- };
- $VAR1 = {
- 'word' => 'ghi',
- 'id' => 3
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement