Saturday, July 7, 2012

My sql affected rows

Mysql affected rows


when you update,delete mysql records number of rows could be affected,but you do not know how many rows deleted or updated.By using mysql_affected_rows() function you could be noticed how many rows affected with your query.
For this post,I used namelist table to delete 9 records by using the row id.

<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('my_database');


mysql_query('DELETE FROM namelist WHERE id < 10');
printf("Records deleted: %d\n", mysql_affected_rows());


?>
Result
Records deleted: 9

No comments:

Post a Comment