Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

postgresql

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?

like image 913
Nikola Avatar asked Feb 22 '26 12:02

Nikola


1 Answers

Use mysql_affected_rows() to get number of affected rows in mysql.

Similary for postgres, it will be pg_affected_rows.

like image 85
Akash KC Avatar answered Feb 25 '26 01:02

Akash KC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!