in reply to Re^2: how to put this db connection code into a function
in thread how to put this db connection code into a function

i don't really want to use the $DBI::errstr as it returns far less information than what is in the $@ variable. That has the line number of the problem plus the statement that was executed, whereas DBI::errstr just has a limited error message
  • Comment on Re^3: how to put this db connection code into a function

Replies are listed 'Best First'.
Re^4: how to put this db connection code into a function
by ikegami (Patriarch) on Jan 05, 2011 at 01:11 UTC
    sub connect { return DBI->connect( "DBI:mysql:".join(';', "database=$sql_database", "host=$sql_host", "port=$sql_port", ), $username, $password, { RaiseError => 1, AutoCommit => 1, }, ); } my $dbh = eval { connect() } or die("Can't connect: $@");