Hello,
I use the DBI module to connect to a mysql database.
First I run a count on a table and I like, if the result of these is query is not 0, to run a delete on this table.
I do this, but I have an error:
Use of uninitialized value in numeric ne (!=) at mysql_epur_function.pl line 116
.
CODE :
$countrowstodelete = $dbh ->prepare("
SELECT count(*) FROM $_[0]
WHERE TO_DAYS(NOW()) - TO_DAYS(eventtimestamp) > 120");
$countrowstodelete->execute;
while ( ($nbcountrowstodelete) =$countrowstodelete->fetchrow() ) {
print "Number of rows to delete $nbcountrowstodelete !\n" ; } ;
if ($nbcountrowstodelete != '0')
{
$deleterows = $dbh ->prepare("
delete from transportlog
WHERE TO_DAYS(NOW()) - TO_DAYS($_[1]) > $_[2]");
$deleterows->execute;
print "Rows deleted\n";
}
else {
print "No rows to delete \n";
};
The problem comes from the if statement because it seams tha the result of the query is not numerci ???
if ($nbcountrowstodelete != '0')
Thanks for your help
I use the DBI module to connect to a mysql database.
First I run a count on a table and I like, if the result of these is query is not 0, to run a delete on this table.
I do this, but I have an error:
Use of uninitialized value in numeric ne (!=) at mysql_epur_function.pl line 116
.
CODE :
$countrowstodelete = $dbh ->prepare("
SELECT count(*) FROM $_[0]
WHERE TO_DAYS(NOW()) - TO_DAYS(eventtimestamp) > 120");
$countrowstodelete->execute;
while ( ($nbcountrowstodelete) =$countrowstodelete->fetchrow() ) {
print "Number of rows to delete $nbcountrowstodelete !\n" ; } ;
if ($nbcountrowstodelete != '0')
{
$deleterows = $dbh ->prepare("
delete from transportlog
WHERE TO_DAYS(NOW()) - TO_DAYS($_[1]) > $_[2]");
$deleterows->execute;
print "Rows deleted\n";
}
else {
print "No rows to delete \n";
};
The problem comes from the if statement because it seams tha the result of the query is not numerci ???
if ($nbcountrowstodelete != '0')
Thanks for your help