Hi, I'm trying to improve my coding and would appreciate if someone could comment and alter my code. I dont know what would work best, named placeholders or question mark placeholders. Place the variables in a array first and then do the binding. Im looking also for solutions regarding record update using place holders. Thanks
$idnrr = 1;
$users = DB::getInstance()->query("SELECT * FROM users WHERE id = :id1", array(':id1' => $idnrr));
if ($users->count()) {
foreach ($users->results() as $result) {
echo $result->name . "<br />";
}
}
public function query($sql, $params) {
$this->_error = false;
if ($this->_query = $this->_pdo->prepare($sql)) {
$x = 1;
if ($this->_query->execute($params)) {
$this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount();
} else {
$this->_error = true;
}
}
return $this;
}