473,388 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

mysql_affected_rows() alternative

Two questions in a row.. I'm on a roll :)

When i perform UPDATEs in my admin system, I'm checking for success by
using mysql_affected_rows() and this works fine if data is changed and
updated.

However, if a user submits an admin page without chaning any details,
the SQL executes fine, but mysql_affected_rows() returns 0 as MySQL is
clever enough to work out that nothing changed.

How do people deal with this? It hampers my error check as
mysql_affected_rows() can be 0 for a perfectly valid update.
Apr 10 '07 #1
5 5220
Tyno Gendo schreef:
Two questions in a row.. I'm on a roll :)

When i perform UPDATEs in my admin system, I'm checking for success by
using mysql_affected_rows() and this works fine if data is changed and
updated.

However, if a user submits an admin page without chaning any details,
the SQL executes fine, but mysql_affected_rows() returns 0 as MySQL is
clever enough to work out that nothing changed.

How do people deal with this? It hampers my error check as
mysql_affected_rows() can be 0 for a perfectly valid update.
Wrong and .. wrong. There is no perfectly valid update and you are not
checking for errors :-)

Add a field time(timestamp) and update "... time = NOW(), ... etc"

--
Arjen
http://www.hondenpage.com - Mijn site over honden
Apr 10 '07 #2
Arjen wrote:
Wrong and .. wrong. There is no perfectly valid update and you are not
checking for errors :-)

Add a field time(timestamp) and update "... time = NOW(), ... etc"
Good idea, then there is always at least a time update. I like. Thanks
Arjen.
Apr 10 '07 #3
On Apr 10, 10:04 am, Tyno Gendo <you@localhostwrote:
Two questions in a row.. I'm on a roll :)

When i perform UPDATEs in my admin system, I'm checking for success by
using mysql_affected_rows() and this works fine if data is changed and
updated.

However, if a user submits an admin page without chaning any details,
the SQL executes fine, but mysql_affected_rows() returns 0 as MySQL is
clever enough to work out that nothing changed.

How do people deal with this? It hampers my error check as
mysql_affected_rows() can be 0 for a perfectly valid update.
>From the manual at <http://www.php.net/mysql_query>
"For other type of SQL statements, UPDATE, DELETE, DROP, etc,
mysql_query() returns TRUE on success or FALSE on error."

So check the return value of mysql_query(), not the value of
mysql_affected_rows().

Apr 10 '07 #4
ZeldorBlat wrote:
"For other type of SQL statements, UPDATE, DELETE, DROP, etc,
mysql_query() returns TRUE on success or FALSE on error."

So check the return value of mysql_query(), not the value of
mysql_affected_rows().
Thanks ZeldorBlat, that's what I was looking for. DATETIME thing Arjen
suggested is good but I figured I was probably missing something very
simple.
Apr 10 '07 #5
On Tue, 10 Apr 2007 15:04:12 +0100, Tyno Gendo <you@localhostwrote:
>Two questions in a row.. I'm on a roll :)

When i perform UPDATEs in my admin system, I'm checking for success by
using mysql_affected_rows() and this works fine if data is changed and
updated.

However, if a user submits an admin page without chaning any details,
the SQL executes fine, but mysql_affected_rows() returns 0 as MySQL is
clever enough to work out that nothing changed.

How do people deal with this? It hampers my error check as
mysql_affected_rows() can be 0 for a perfectly valid update.
In addition to the other good answers: MySQL does have a mode where you can
override the "optimised" no-changes update, and actually give you the number
matching the WHERE clause rather than those changed.

The C API says to pass CLIENT_FOUND_ROWS when connecting, to change the
behaviour of mysql_affected_rows(). Looking at the PHP manual, it appears that
this flag may not yet be supported.

http://uk2.php.net/manual/en/ref.mys...l.client-flags

However, I've not looked further than the manual, so it may still be worth
digging through the API and possibly raising this as a feature request on:

http://bugs.php.net
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Apr 11 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben | last post by:
Hi all, I want to store unique data about my page visit. This is done using cookie value. In my database, the page name and cookie value(ip address) are both primary keys. This ensures unique...
99
by: Paul McGuire | last post by:
There are a number of messages on the python-dev mail list that indicate that Guido is looking for some concensus to come from this list as to what *one* alternative syntax for decorators we would...
28
by: Paul McGuire | last post by:
Well, after 3 days of open polling, the number of additional votes have dropped off pretty dramatically. Here are the results so far: Total voters: 55 (with 3 votes each) Votes for each choice...
1
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a...
3
by: Will McGugan | last post by:
Hi, Is there a naming convention regarding alternative constructors? ie static methods where __new__ is called explicity. I use lower_case for methods in general, but thought maybe CamelCase...
0
by: sachintandon | last post by:
Hello all, Thanks in advance for your help I have a problem in sending emails, my requirement is to send multipart alternative emails with attachments, I'm able to send text with attachments or...
11
by: Francine.Neary | last post by:
I've read that as well as "normal" Java-like function definitions, e.g. int main(int argc, char **argv), you can also choose to use an alternative syntax, i.e. int main(argc, argv) int argc;...
5
by: MS | last post by:
Hi, I'm doing a table insert and have a question about mysql_affected_rows(). The following code works. It correctly inserts the row and mysql_affected_rows() returns 1 as it should do. ...
3
by: Sandman | last post by:
Hi, So I read the manual where it says to use mysql_affected_rows() for everything except SELECT and SHOW, and use mysql_num_rows() for those two, which actually return a result. However, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.