Hello, please can some one help me figure this out…
I use pdo and create classes with the methods i need for each page or script. This has become a bit of a pain as now i have many methods inside many classes and i want 90% of them to come from one class that i’ll call CRUD and inside just have insert, select, update, delete methods.
How can i get around sql injections in my select example bellow… The idea is to end up with dynamic selecting etc to cut down the number of methods i have!
class CRUD {
private $pdo;
public function __construct(PDO $pdo) {
$this->pdo = $pdo;
}
public function select($table) {
$sql = "SELECT * FROM ";
$sql .= $table;
$stmt = $this->pdo->prepare($sql);
$stmt->execute();
return $stmt->fetch();
}
}
$sitePDO = (new CRUD($sitePDO));
var_dump($sitePDO->select('settings')['site_name']);
Thanks for your time, hope all are well in these crappy times!