当我插入一条记录时,收到消息“受影响的第1行”,同时更新“行匹配:1已更改:1”
如何从PHP代码获取这些消息?
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
解决方法:
您可以使用mysql_affected_rows()方法:
$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());
标签:mysql,php
来源: https://codeday.me/bug/20191106/2001604.html