Check mysql_query results if DELETE query worked?

I have a DELETE request that removes a record from mysql db.

is there any way to verify that the removal is complete or not?

I mean, for the APPOINTMENT request, you do

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

and you will get nr returned rows.

Is there a similar method to delete records?

thanks

+4
source share
2 answers

Use mysql_affected_rows() . It does not require an answer as a parameter.

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

In addition, I love PDO better than the classic mysql_ functions. Just saying it.

+4
source

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

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

Source: https://habr.com/ru/post/1311735/


All Articles