Php mysqli affected_rows

I am just doing some tests with this and I cannot figure out if I am doing this correctly. The request will update the string .. But affected_rows always returns 0 .. Why?

<?php $connection = new mysqli('localhost', 'user', 'pass', 'db'); if (mysqli_connect_errno()) { printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error()); exit; } $email = $connection->real_escape_string($_GET['email']); $activation = $connection->real_escape_string($_GET['hash']); //$query = $connection->query("SELECT email, activationCode, active FROM users WHERE email='".$email."' AND hash='".$activation."' AND active='0'"); $select = $connection->query("UPDATE users SET active = '1' WHERE email='".$email."' AND activationCode='".$activation."' AND active='0'"); printf("Affected rows (UPDATE): %d\n", $select->affected_rows); $connection->close(); ?> 
+4
source share
1 answer

$select->affected_rows is written $select->affected_rows and not $connection->affected_rows .

$select->affected_rows contains information about how many rows were affected by the last query (which could be successful or not), while the connection contains a database manager object that contains data about the results of the query.

+6
source

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


All Articles