4

I have a DELETE query which deletes a record from a mysql db.

is there any way to make sure if the delete was performed or not?

I mean, for a query to FIND stuff you do

     $res=mysql_query($var);
     $nr=mysql_num_rows($res);

and you get nr of rows returned.

Is there any similiar method for deletion of records?

Thanks

2 Answers2

4

Use mysql_affected_rows(). It does not require the response as a parameter.

mysql_query('DELETE FROM whatever');
$num = mysql_affected_rows();

Also, I like PDO better than the classic mysql_ functions. Just saying.

Matchu
  • 83,922
  • 18
  • 153
  • 160
0

mysql_affected_rows() extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead,the MySQLi or PDO_MySQL extension should be used.

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$mysqli->query("DO SOMETHING");
$mysqli->affected_rows;