1. Die SQL-Anweisung vorbereiten. 2. Die SQL-Anweisung ausfuehren. 3. Die Ergebnisse abrufen. 4. Die SQL-Transaktion beenden. # 1. prepare statement handle $sth $cmd = 'SELECT * FROM table WHERE id = ? AND date > ?'; my $sth = $dbh->prepare_cached($cmd) or croak "SQL prepare failed '$cmd': " . $dbh->errstr; # 2. execute statement (via its handle) my $rc = $sth->execute(parameter1, parameter2, ...); # execute() has as many arguments as the prepared statement ?'s has unless(defined $rc) { croak "SQL command failed: " . $dbh->errstr; } else { # $rc rows had been effected, e.g. by UPDATE commands } # 3. fetch results [if any] (again via its handle) while(my $result = $sth->fetchrow_arrayref) { # ARRAY ref $result has one entry per column # $result->[0] - first column, etc. } croak "Failed to get results from SQL command: " . $dbh->errstr if $sth->err; - -or- while(my $result = $sth->fetchrow_hashref) { # HASH ref $result has coumn_name => value pairs # $result->{name1}, $name->{name2}, ... } croak "Failed to get results from SQL command: " . $dbh->errstr if $sth->err; # 4. finish DB transaction (via DB handle) $dbh->commit() or die "Failed to save modified data: " . $dbh->errstr; - -or- $dbh->rollback() or die "Failed to discard modified data: " . $dbh->errstr;