How can I make sure that DELETE SQL statement in Postgres using PHP was successfull?

I’m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.
My question was:
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;
?>
The answer, by LolCoder, was:
Use mysql_affected_rows() to get number of affected rows in mysql.
Similary for postgres, it will be pg_affected_rows.





Leave a Comment