Fehlerbehandlung bei DBI->schließen

Neben handling-Fehlers mit standard-code, die "Unfähig zu verbinden: $DBI::errstr\n" ist es möglich, schreiben Sie eine benutzerdefinierte code wie unten?

Standard:

$dbstore = DBI->connect($dsn, $user, $pw,
    {ora_session_mode => $mode, PrintError => 0, RaiseError => 0, AutoCommit => 0}) 
    or die "Unable to connect: $DBI::errstr\n";

Custom:

$dbstore = DBI->connect($dsn, $user, $pw,
    {ora_session_mode => $mode, PrintError => 0, RaiseError => 0, AutoCommit => 0});

if (!$dbstore)
{
    CUSTOM_LOG_HANDLER("Could not connect to database: $DBI::errstr");
    return;
}

Probe-Standard-Code:

#!/usr/bin/perl

# PERL MODULES WE WILL BE USING
use DBI;
use DBD::mysql;

# HTTP HEADER
print "Content-type: text/html \n\n";

# CONFIG VARIABLES
$platform = "mysql";
$database = "store";
$host = "localhost";
$port = "3306";
$tablename = "inventory";
$user = "username";
$pw = "password";

#DATA SOURCE NAME
$dsn = "dbi:mysql:$database:localhost:3306";

# PERL DBI CONNECT (RENAMED HANDLE)
$dbstore = DBI->connect($dsn, $user, $pw) or die "Unable to connect: $DBI::errstr\n";

Danke für Sie Zeit.

Gibt es andere Wege, um würdevoll beenden, ohne Fehler, die immer angemeldet sind, in der web-server-logs?

InformationsquelleAutor Hozy | 2011-07-11

Schreibe einen Kommentar