php - Does not update in boolean field

1

I'm trying to update user data, but the active field is not updated.

I have tried several changes and also changed the value of the variable $active from boolean to int , but without success.

Another behavior I noticed is when I do not make any changes to the fields and I have to execute the update, $stmt->affected_rows returns 0, is this normal?

public function user_update($user_id, $name, $email, $active)
{
    $stmt = $this->conn->prepare("UPDATE users SET user_name = ?, user_email = ?, user_active = ? WHERE user_id = ?");
    $stmt->bind_param("ssbi", $name, $email, $active, $user_id);
    $stmt->execute();
    $num_affected_rows = $stmt->affected_rows;
    $stmt->close();
    return $num_affected_rows > 0;
}

The version of php is 5.6.22, and the base is MySQL

    
asked by anonymous 06.06.2016 / 02:35

1 answer

2

b is for blob and nonboolean fields / values, change b to i if you are passing 0 or 1. Or change to s to t or f / p>

$stmt->bind_param("ssii", $name, $email, $active, $user_id);
    
06.06.2016 / 16:04