Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Data short summary.
- *
- * Data description.
- *
- * @version 1.0
- * @author liran
- */
- class Data
- {
- protected $dbh;
- protected $stmt;
- public function __construct(){
- $this->dbh = new PDO("mysql:host=".DB_HOST.";dbname=". DB_NAME, DB_USER, DB_PASS);
- }
- public function query($query){
- $this->stmt = $this->dbh->prepare($query);
- }
- //Binds the prep statement
- public function bind($param, $value, $type = null){
- if (is_null($type)) {
- switch (true) {
- case is_int($value):
- $type = PDO::PARAM_INT;
- break;
- case is_bool($value):
- $type = PDO::PARAM_BOOL;
- break;
- case is_null($value):
- $type = PDO::PARAM_NULL;
- break;
- default:
- $type = PDO::PARAM_STR;
- }
- }
- $this->stmt->bindValue($param, $value, $type);
- }
- public function execute(){
- $this->stmt->execute();
- }
- public function resultSet(){
- $this->execute();
- return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
- }
- public function lastInsertId(){
- return $this->dbh->lastInsertId();
- }
- public function single(){
- $this->execute();
- return $this->stmt->fetch(PDO::FETCH_ASSOC);
- }
- public function clearstr($str) {
- return $this->dbh->quote($str);
- }
- private function isInteger($input){
- return(ctype_digit(strval($input)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement