programming-examples/perl/Database/Delete a record from the database.pl

33 lines
671 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/usr/bin/perl
use warnings;
use strict;
use DBI;
use DBD::ODBC;
my $dbh = DBI->connect( "dbi:ODBC:employeeDB", "", "", { RaiseError => 1 } );
my $IDdel = "1";
my $query = "DELETE FROM employee WHERE EmployeeID = '$IDdel'";
print( "$query \n\n" );
$dbh->do( $query );
my $sth = $dbh->prepare( q{ select * FROM employee } );
$sth->execute();
my @array;
while ( @array = $sth->fetchrow_array() ) {
write( STDOUT );
}
# Clean up
warn( $DBI::errstr ) if $DBI::err;
$dbh->disconnect();
$sth->finish();
format STDOUT =
@<<<<<<@<<<<<<<<<@<<<<<<<<<<@<<<<<@<<<<<<<<<<<
$array[ 0 ], $array[ 1 ], $array[ 2 ], $array[ 3 ], $array[ 4 ]