logging MySQL response from PHP page
When I insert a record, I get the message "1 row affected开发者_如何学Go" and while updating "Rows matched:1 Changed:1" How do I get these messages from PHP code?
mysql> insert into mytest values ('103');
Query OK, 1 row affected (0.26 sec)
mysql> update mytest set id = 12 where id = 10;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
You can use the mysql_affected_rows()
method:
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');
mysql_query('insert into mytest values ('103');');
printf("Records inserted: %d\n", mysql_affected_rows());
mysql_query('update mytest set id = 12 where id = 10;');
printf("Records updated: %d\n", mysql_affected_rows());
Those strings only exist in the context of the mysql
CLI tool; they aren't actually sent by the server. See mysql_affected_rows()
and mysql_num_rows()
.
Check out mysql_affected_rows
and mysqli_affected_rows
精彩评论