Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Attributes

  • attributes|dbi
  • AutoCommit
  • PrintError
  • RaiseError
  • NAME_lc
  • FetchHashKeyName
  • TraceLevel

In addition to the connection string, the username and the password one can and should configure the database with the DBI specific configuration options (or attributes). These options all go in a HASH reference in the 4th parameter of the DBI connect method.

As the databases and the DBD - Database drivers might all decide arbitrarily on their mode regarding transactions one should always explicitly declare how she wants to operate.

The AutoCommit option.

my %attributes = (
    PrintError  => 1,
    RaiseError  => 1,
    AutoCommit  => 1,
    FetchHashKeyName => 'NAME_lc',  #   NAME_uc
    TraceLevel  => 1,  # see Debugging and Trace levels later
);

my $dsn = "dbi:SQLite:dbname=$dbfile";
my $dbh = DBI->connect($dsn, $username, $password, \%attributes);