So I have this incomplete method to save object in database:
public function save() {
$variables = get_object_vars($this);
$attributes = [];
foreach ($variables as $variable => $value) {
$attributes[] = $value;
}
$variableString = implode(", ", $attributes);
foreach ($variables as $variable => $value) {
$attributes[] = ":" . $value;
}
$valueString = implode(", ", $attributes);
$sql = "INSERT INTO products (" . $variableString . ") VALUES (" . $valueString . ")";
$query = $this->pdo->prepare($sql);
// ...
}
How do I bind values like this using arrays I already created?
$query->execute(array(
':username' => $username,
':email' => $email,
':password' => $password
));