Logging MySQL response on PHP page

When I insert a record, I get the message "1 line is affected" and when updating "Lines match: 1 Changed: 1" How to 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
+3
source share
3 answers

You can use the method 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());
+3
source

These lines exist only in the context of the CLI tool mysql; they are not actually sent by the server. See mysql_affected_rows()and mysql_num_rows().

+1
source

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


All Articles