public function save(User $user_object)
{
$data = array();
$data[] = $user_object->username;
$data[] = $user_object->email;
$data[] = $user_object->password;
if (is_null($user_object->id)) {
$data[] = $user_object->salt;
$data[] = time();
$sth = $this->db->prepare("INSERT INTO users (username, email, password, salt, created) VALUES (?, ?, ?, ?, ?)");
$sth->execute($data);
} else {
//Update User
}
}
As you can see if there is no id there will be an insert if there is an ID however, there will be a update.. However I am not sure how the UPDATE statement in PDO will look like, I want to push in all data that is in the array where the ID = $user_object->id.
There is no “UPDATE statement in PDO”. There is just usual SQL UPDATE query. PDO does not have it’s own SQL. it is just an API to send SQL query to the DB server.
So, just write usual SQL with placeholders