1

Possible Duplicate:
How to know how many mysql lines updated

I want to do something like this with php: IF(UPDATE rows FROM table_name){ Do something }

My case is, I need to do some operations as long as they have updated some tables in my database.

Is there any function or SQL statement to see if my tables have been updated?

Community
  • 1
  • 1

3 Answers3

2

Use

if(mysql_affected_rows ($link)>0) {
}
silly
  • 7,789
  • 2
  • 24
  • 37
  • This function work if I update or do something with mysql_query. But, in this case The update is done from phpmyadmin. Or not? – Eduardo Gabriel Cabrera Japa Feb 20 '12 at 17:17
  • In phpMyAdmin, when you run an update query (assuming your query is free of errors) it will post the affected rows and the time the query took to run like so: _Affected rows: 0 (Query took 0.0070 sec)_ – Carrie Kendall Feb 20 '12 at 17:32
1

There is nothing in MySQL that will tell you if a record "has ever been updated", outside of determining how many rows were affected by the last update, or viewing the logs.

If you need to detect if a record has been updated (from anywhere), you are really saying, "is my record different than x?". Therefore, you must store x somewhere.

Many people create a created_date field and a modified_date field on a table and update the dates accordingly. When you insert the record, you set the created_date. Whenever you update the record, you set the modified_date. Then, any record that has a modified_date has been "updated".

If your application isn't capable of inserting the date values, you can use a trigger.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
0

I am not sure what you are after, but you could use:

if (mysql_affected_rows($connection) > 0) {
}

Also, if you want to do things on the database-side, define a trigger, which launches if a record is updated.

Pateman
  • 2,727
  • 3
  • 28
  • 43