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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.