| 
<?php 
// @ PDO Prepared MySQL Statements Class v2.0
 // @ Developed by Takis Maletsas
 // @ 2016
 class DB
 {
 private $dbh = null;
 public function __construct($db_host = "localhost", $db_name = "database", $db_user = "root", $db_pswd = "")
 {
 $this->dbh = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pswd);
 $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
 public function query()
 {
 $args = func_get_args();
 $sth  = $this->dbh->prepare($args[0]);
 for ($i = 1; $i < count($args); $i++)
 $sth->bindParam($i, $args[$i], $this->type($args[$i]), strlen($args[$i]));
 return $sth->execute();
 }
 public function fetch()
 {
 $args = func_get_args();
 $sth  = $this->dbh->prepare($args[0]);
 for ($i = 1; $i < count($args); $i++)
 $sth->bindParam($i, $args[$i], $this->type($args[$i]), strlen($args[$i]));
 $sth->execute();
 return $sth->fetchAll(PDO::FETCH_ASSOC);
 }
 private function type($arg)
 {
 return is_int($arg) ? PDO::PARAM_INT : (is_bool($arg) ? PDO::PARAM_BOOL : PDO::PARAM_STR);
 }
 }
 ?>
 |