Reputation: 15038
Is there a function which would return true of false based on if the DELETE SQL statement succeded or not? For example something like this:
<?php
$sql = "DELETE FROM table WHERE id=123";
$result = pg_query($sql);
if **function**($result)
return true;
else
return false;
?>
Further more, is there maybe a function which returns the number of successfully deleted rows?
Upvotes: 3
Views: 2335
Reputation: 2703
if()
is the function ;)
if($result)
return true;
else
return false;
If you want to know number of successfully deleted rows,loop the if condition
$flag=0;
if($result)
{
$flag++;
}
if($flag==0;)
echo "Nothing is deleted";
else
echo $flag." rows are deleted";
Upvotes: 2
Reputation: 16310
Use mysql_affected_rows() to get number of affected rows in mysql.
Similary for postgres, it will be pg_affected_rows.
Upvotes: 5
Reputation: 9823
if($result)
{
// Delete was successful
}
else
{
// was not successful
}
Upvotes: 1