4

我只是在做一些测试,我不知道我是否以正确的方式做这件事。查询将更新该行。但affected_rows 总是返回0 .. 为什么?

<?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

1 回答 1

6

它说$select->affected_rows而不是$connection->affected_rows

$select->affected_rows包含有关上次查询(可能成功或失败)影响多少行的信息,而 connection 包含包含有关查询结果的数据的数据库管理器对象。

于 2011-03-25T21:16:33.553 回答