Jump to content

Checking result of MySQL UPDATE query


Earthenware

Recommended Posts

Hi,

 

I have a feeling that this is an obvious one but I can’t seem to find an answer. I am trying to evaluate the result of an UPDATE query.

 

My syntax works fine and my DB gets updated as expected. My problem is that if I put a non-existent value in my WHERE clause, I don’t get warned about it.

 

I’m doing this:

 

error_reporting(E_ALL);

$query  = "update <TABLE> set <FIELD1> = '<VALUE1>' where <FIELD2> = '<VALUE2>'";

$result = mysql_query ($query, $db)

        or die ("Query failed: " . mysql_error() . " Actual query: " . $query);

 

The result is the same whether VALUE2 exists in the DB or not. $result is always returned as ‘1’.

 

According to dev.mysql.com, “UPDATE returns the number of rows that were actually changed”, but I get ‘1’ whether a row was changed or not.

 

My goal of course is to have the script notify me if the record that I am trying to update doesn’t exist. That is what is not happening at the moment.

Link to comment
https://forums.phpfreaks.com/topic/254475-checking-result-of-mysql-update-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.