i'm working with PHP for some weeks now and with the time i am asking myself, if it is possible to handle all database-queries (SELECT, UPDATE, INSERT, DELETE) with a single function.
At the moment i have round about 30x of these "try-catch" PDO's to communicate with my database:
//DB connection info already set...
try {
$exc = $this->dbh->prepare("SELECT uid FROM users WHERE email = :mail");
$exc->bindParam(':mail', $mail, PDO::PARAM_STR);
$exc->execute();
$exc->setFetchMode(PDO::FETCH_ASSOC);
while ($row = $exc->fetch()) {
// do something with $row['uid']
}
$this->dbh = null;
$exc = null;
} catch (PDOException $e) {
echo $e;
$this->dbh = null;
$exc = null;
}
Is there a way to minify this code by using a single function and do i or the server get any profit of this ?
Thank you, Louis