3

Basically, I have two SQL DELETE queries that a PHP script processes. However, I want the second query to be executed only if the first one successfully deletes a row in the designated table.
So is there anyways to have the mysql_query() function return true or false or something, after executing the first query?

If there is no way to do so, then I've already come up with a method for achieving the result I want. However, being able to do it this way would be much simpler, and make much more sense as far as the logic of my code is concerned.

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
fvgs
  • 19,524
  • 8
  • 30
  • 46
  • Please, stop using `mysql_query`. This is an interface from the 1990s that's being phased out and may not be supported in the future. Use `mysqli` or PDO before you create a mess that will take forever and a half to clean up. [It's not that hard to pick up](http://bobby-tables.com/php) and will save you a lot of trouble in the future. – tadman Aug 25 '12 at 06:17

2 Answers2

3

You can do:

delete ....
select row_count()

That will give you the number of rows deleted (or 0 if none). For more information: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_row-count

Aapo Kyrola
  • 1,060
  • 8
  • 8
1

I think you are looking for something a little more official like transactions with mySQL.

There is a useful post on the stack about this very situation.

Community
  • 1
  • 1
ZombieCode
  • 1,597
  • 2
  • 22
  • 43