mysqli_prepare statment行没有更新

时间:2016-06-18 10:05:54

标签: php mysqli prepared-statement

以下功能正在执行$stmt并打印成功,但它显示零行已更新。如果我手动运行sql,它将更新数据库。但它没有从下面的PHP代码更新。我错过了什么吗?

 function updateLastActive($link, $id) {

    $stmt = mysqli_prepare($link,"update `account` set `lastActive` =now() where  id = ?"); 
    mysqli_stmt_bind_param($stmt, 'i', $id);
    if(mysqli_stmt_execute($stmt)){
        $num_of_rows = $stmt->num_rows; 
        echo 'success';
        echo $num_of_rows;
        return 1;
    }else{
        return 0;
    }}

1 个答案:

答案 0 :(得分:1)

mysqli_affected_rows()

  

返回受上一次INSERT,UPDATE影响的行数,   REPLACE或DELETE查询。

使用mysqli_affected_rows()代替$stmt->num_rows

 if (mysqli_stmt_execute($stmt)) {
        $num_of_rows = mysqli_affected_rows($link));
        echo 'success';
        echo $num_of_rows;
        return 1;
    } else {
        return 0;
    }