I want to make an easy function inside a class that can update each cell in a database.
Like I now can use echo $user->cell('email');
to retrieve the email, I want to update it with
$user->update('email','new@email.com');
But for as far as I know, bind_param()
doesn't support "?=?" in the query.
Anybody a safe solution to that?
class User{
private $details;
private $id;
function __construct($userId){
$db = Database::getInstance();
$mysqli = $db->getConnection();
$stmt = $mysqli->prepare("SELECT * FROM users WHERE id=?");
$stmt->bind_param("i",$userId);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows == 1){
$this->details = $result->fetch_assoc();
$GLOBALS['userId'] = $userId;
}
$stmt->close();
}
function cell($cell){
return $this->details[$cell];
}
function update($cell,$value){
$db = Database::getInstance();
$mysqli = $db->getConnection();
$stmt = $mysqli->prepare("UPDATE users SET ?=? WHER id=".$this->id);
$stmt->bind_param("ss",$cell,$value);
$stmt->execute();
return true;
}
}