How can we know if a MySQL UPDATE was successfull

Hello,

How can we know that a MySQL UPDATE was successful in actually updating a Row?

I mean lets say this is the UPDATE:

UPDATE xyz SET
me = me + 1
WHERE id = 1000
AND date = CURDATE()
LIMIT 1;

How can we know, without doing a SELECT, that this UPDATE actually did UPDATE a row?
Again, without using a SELECT command to check this, but just looking to the MySQL query of above UPDATE.

Thanks,

Test the value returned from affected_rows() - if it is zero then nothing was updated. If it is one then the row was updated.

that’s a php function, right?

what’s the mysql equivalent?

not everyone uses php

ROW_COUNT()

Hi,

Are you saying that is for example the Php code is like:

$sql_upd = “UPDATE…”
$query_upd = msql_querry($sql_upd);

that then:

affected_rows($query_upd) will tell us how many rows were effected so that the;

if (affected_rows($query_upd) == 0) {
echo ‘No Update’;
] else {
echo ‘Update was OK’;
}

There is NO function
affected_rows
in Php!

and this is not a MySQL Php command too!

Try this:
http://www.php.net/manual/en/function.mysql-affected-rows.php

Hey Thanks.
But someone on another forum got me the answer I was looking for and this was solved.
But thank you all for your answers.

For the benefit of others, please tell us the solution that solved your problem.

Here is what go the Job done:

$query_upd = mysql_query($sql_upd);

if (mysql_affected_rows() == 0) {
echo ‘No Update was Done’;
} else {
echo ‘Update was OK’;
}

Thankyou

You welcome :slight_smile: