Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* ____ _ _ __ _______ ____
- / ___|| |__ ___ | |\ \ / / ____| __ )
- \___ \| '_ \ / _ \| __\ \ /\ / /| _| | _ \
- ___) | | | | (_) | |_ \ V V / | |___| |_) |
- |____/|_| |_|\___/ \__| \_/\_/ |_____|____/
- ShotWEB - Content Management System.
- Build on Monsma's MVC Application Framework.
- Copyright (C) 2012 Monsma & Wesley. All rights reserved.
- Website: http://www.shothotel.nl/ - http://www.blackcoders.eu/
- */
- if(!defined('IN_SHOTWEB') ? die('Sorry, you cannot access this file.') : null);
- class DatabaseDriver implements iDatabaseDriver
- {
- public $Query, $STMT, $Connection, $Connected, $Param;
- private $Config, $hostname, $username, $password, $database;
- public function __construct()
- {
- global $Application;
- $this->Config = $Application->Config['mysql'];
- if($this->Connected == false)
- {
- $this->Connect();
- }
- }
- public function Connect()
- {
- try
- {
- $dsn = "mysql:dbname={$this->Config['database']};host={$this->Config['hostname']}";
- $this->Connection = new PDO($dsn, $this->Config['username'], $this->Config['password'], array(PDO::ATTR_PERSISTENT => true));
- }
- catch(PDOException $Exception)
- {
- throw new exception($Exception->getMessage());
- }
- $this->Connected = true;
- }
- public function Disconnect()
- {
- if($this->Connected == true)
- {
- $this->Connection = null;
- $this->Connected = false;
- }
- }
- public function Secure($value)
- {
- return stripslashes(htmlentities($value));
- }
- public function Query($value)
- {
- $this->Query = $value;
- if(!$this->STMT = $this->Connection->prepare($value))
- {
- throw new exception($this->STMT->error);
- }
- return $this;
- }
- public function Bind($param)
- {
- $this->param = $param;
- if(!is_array($param))
- {
- throw new exception('Bind Error: bind the params in a array!');
- }
- return $this;
- }
- public function Run()
- {
- if(!$this->STMT->execute($this->param))
- {
- throw new exception($this->STMT->error);
- }
- return new DatabaseObject(null, $this->STMT);
- }
- }
- class DatabaseObject implements iDatabaseObject
- {
- private $STMT;
- public function __construct($query, $link)
- {
- $this->STMT = $link;
- }
- public function result()
- {
- return $this->STMT->fetchColumn();
- }
- public function fetch_array()
- {
- return $this->STMT->fetch(PDO::FETCH_ASSOC);
- }
- public function num_rows()
- {
- return $this->STMT->rowCount();
- }
- }
- ?>
- // Voorbeeld
- $Query = "UPDATE user_stats SET DailyRespectPoints = ?, DailyPetRespectPoints = ?";
- Core::$DB->Query($Query)->Bind(array($number, $number))->Run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement