Deleting Entries : MySql « Database « Perl






Deleting Entries

   

use DBI;
my $driver="DBI:mysql";
my $database="sample_db";
my $user="root";
my $host="localhost";

my $dbh = DBI->connect("$driver:database=$database;host=$host;user=$user") or die "Can't connect: " . DBI->errstr;

print "Name: ";
chomp($name=<STDIN>);
my $sth=$dbh->prepare('SELECT count(*) from Employee WHERE name = ?');
$sth->execute($name);
print "Number of rows to be deleted: ", $sth->fetchrow_array(), "\n";

$num=$dbh->do(qq/DELETE from Employee WHERE name = ?/, undef,$name);
print ($num > 1 ?"$num rows deleted.\n":"$num row deleted.\n");

$sth->finish();
$dbh->disconnect();

   
    
    
  








Related examples in the same category

1.Dumping a Query's Results
2.Error Diagnostic Variables
3.Handling Quotes
4.Inserting into a Database
5.Load text file to database
6.MySQL Data Types
7.Preparing a Statement Handle and Fetching Results
8.Pushing Query Results to an Array to Find Wildcard Hosts
9.Query parameter binding
10.Retrieving Query Results Listing MySQL Users and Hosts
11.Retrieving an Index ID