Nikola
Nikola

Reputation: 15038

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

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

Answers (3)

Bhuvan Rikka
Bhuvan Rikka

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

Akash KC
Akash KC

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

asprin
asprin

Reputation: 9823

if($result)
{
  // Delete was successful
}
else
{
  // was not successful
}

Upvotes: 1

Related Questions