Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Elvis Halilovic
- * @copyright Elvis Halilovic
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package core\system\database
- */
- namespace core\system\database;
- class database {
- private $DB,
- $STMT,
- $OPTIONS = array(\PDO::ATTR_PERSISTENT => true, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION),
- $HOST,
- $USER,
- $PASS,
- $DATA;
- public $RESULT = null,
- $INSTANCE;
- public function __construct() {
- $this->HOST = \HMConfig::DATABASE_HOST;
- $this->USER = \HMConfig::DATABASE_USER;
- $this->PASS = \HMConfig::DATABASE_PASS;
- $this->DATA = \HMConfig::DATABASE_NAME;
- $this->connect();
- }
- private function connect() {
- try {
- $this->DB = new \PDO("mysql:host={$this->HOST};dbname={$this->DATA}", $this->USER, $this->PASS, $this->OPTIONS);
- } catch (\PDOException $ex) {
- echo $ex->getMessage();
- }
- return $this;
- }
- public function query($query){
- $this->STMT = $this->DB->prepare($query);
- }
- 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 bindArray($array) {
- foreach($array as $key => $value) {
- $this->bind($key, $value);
- }
- return true;
- }
- public function execute() {
- return $this->STMT->execute();
- }
- public function getAllData() {
- $this->execute();
- return $this->STMT->fetchAll(\PDO::FETCH_ASSOC);
- }
- public function getData() {
- $this->execute();
- return $this->STMT->fetch(\PDO::FETCH_ASSOC);
- }
- public function rowCount() {
- return $this->STMT->rowCount();
- }
- public function lastInsertId() {
- return $this->DB->lastInsertId();
- }
- public function beginTransaction() {
- return $this->DB->beginTransaction();
- }
- public function endTransaction() {
- return $this->DB->commit();
- }
- public function cancelTransaction() {
- return $this->DB->rollback();
- }
- public function debugDumpParams() {
- return $this->STMT->debugDumpParams();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement