How to update a specific row OR RETURN FALSE if it does not exist?

How to do it in one request?

+3
source share
3 answers

You can do something like:

function updateValue()
{
     mysql_query($sql); // your update goes here
     return mysql_affected_rows() > 0;
}

From the comment of BoltClock:

Keep in mind that mysql_affected_rows () returns 0 if the row exists, but the old and new values ​​are equal (which means no update is required).

+4
source

You can use the mysql_affected_rows () function to check if any update lines have affected. See http://php.net/manual/en/function.mysql-affected-rows.php for details

+1
source

.

if(mysql_query('UPDATE table SET key = value WHERE id = 33')){/*....*/}

where , , , , ?

+1

Source: https://habr.com/ru/post/1771156/


All Articles