★ wanayoo — archive 1999 http://www.php.net/manual/function.mysql-affected-rows.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to MySQL
Quick Reference
MySQL
* mysql_affected_rows
* mysql_change_user
* mysql_close
* mysql_connect
* mysql_create_db
* mysql_data_seek
* mysql_db_query
* mysql_drop_db
* mysql_errno
* mysql_error
* mysql_fetch_array
* mysql_fetch_field
* mysql_fetch_lengths
* mysql_fetch_object
* mysql_fetch_row
* mysql_field_name
* mysql_field_seek
* mysql_field_table
* mysql_field_type
* mysql_field_flags
* mysql_field_len
* mysql_free_result
* mysql_insert_id
* mysql_list_fields
* mysql_list_dbs
* mysql_list_tables
* mysql_num_fields
* mysql_num_rows
* mysql_pconnect
* mysql_query
* mysql_result
* mysql_select_db
* mysql_tablename
Manual: mysql_affected_rows
View the source code for this pageSearch the site



Previous page
 MySQL
mysql_change_user 
Next page


mysql_affected_rows

mysql_affected_rows -- Get number of affected rows in previous MySQL operation

Description

int mysql_affected_rows(int [link_identifier] );

mysql_affected_rows() returns the number of rows affected by the last INSERT, UPDATE or DELETE query on the server associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed.

If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero.

This command is not effective for SELECT statements, only on statements which modify records. To retrieve the number of rows returned from a SELECT, use mysql_num_rows().


User Contributed Notes: mysql_affected_rows


mdavidson@cjp.com
22-Nov-1999 11:36
Here's a question: Why does the manual say that mysql_affected_rows does not work with SELECT statements, when, in fact, it does? Is it something being kept in for backwards compatibility?


cterreNO@activ.esSPAM
01-Dec-1999 11:12
Why do I keep getting 5302368 as the result of a mysql_affected_rows() call after a mysql_query("insert...",...) that I know has affected just 1 successful insert??? I am totally bugged :-(


rattlesnake@UniNova.zzn.com
21-Dec-1999 04:20
This might seem obvious to some, but this returns the number of rows that have literally been *affected* by the SQL command; i.e., it will return zero if it matches rows but does not change them. For example, if you use an UPDATE command and it matches a record but no values change, this will return zero. If you are using a zero return as an indication of error, this will not make a sensible match for your logic! (You wouldn't programmatically update equal values, but a user might 'update' a record with the values that already existed, which should probably *not* be considered an error condition.)


jeffrey@thompsonic.com
26-Dec-1999 09:14
mysql_affected_rows() is returning the correct value (1) for me, even if none of the values change. I'm using PHP 4.03b.
Happy Hacking!
Jeffrey Thompson, President
Thompson Internet Communications, Inc.
http://www.thompsonic.com



ignacio@windsurf.cl
03-Feb-2000 09:34
When I try to insert a row, i.e. INSERTing, I get -1 !!!! Is this a message or what? :(


dante@hearme.com
28-Mar-2000 11:18
I was getting that "-1" value from the mysql_affected_rows() as well, but then I realized that I DID have an error in my INSERT statement. I was saying INSERT INTO tblTrack colCount, colDate VALUES (1, NOW()) .... when I should have said INSERT INTO tblTrack (colCount, colDate) VALUES (1, NOW())... Maybe you have an error as simple as this too ;)


 About Notes


Previous page
 MySQL
mysql_change_user 
Next page



Site Statistics


Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.