Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once ($_SERVER['DOCUMENT_ROOT'] . '/Mysong/AutoLoad.php');
- class Query
- {
- private $dbh;
- private $stmt;
- public function __construct()
- {
- $connection = new DbConnection;
- if($this->dbh = $connection->dbh){
- return;
- } else {
- echo " Unable to Connect to DB...";
- }
- }
- public function query($query)
- {
- if($this->dbh != NULL){
- $this->stmt = $this->dbh->prepare($query);
- } else {
- exit;
- }
- }
- 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()
- {
- return $this->stmt->execute();
- }
- public function resultSet()
- {
- $this->execute();
- return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
- }
- public function single()
- {
- $this->execute();
- return $this->stmt->fetch(PDO::FETCH_ASSOC);
- }
- public function asObject()
- {
- $this->execute();
- return $this->stmt->fetch(PDO::FETCH_OBJ);
- }
- public function rowCount()
- {
- return $this->stmt->rowCount();
- }
- public function findAll($table)
- {
- $sql = "SELECT * FROM $table";
- $this->stmt = $this->dbh->prepare($sql);
- $this->stmt->execute();
- return $this->stmt->fetchAll();
- }
- public function closeDb()
- {
- return $this->dbh = NULL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement