Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.17 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Serenity
  5.  * Date: 30-sep-2010
  6.  * Time: 15:08:44
  7.  * To change this template use File | Settings | File Templates.
  8.  */
  9. include('result.php');
  10. class Mysql {
  11.  
  12.     private $connection;
  13.     private $database;
  14.  
  15.     private static $executed_querys;
  16.  
  17.  
  18.     public function __construct($host = '', $user = '', $pass = '', $database = '') {
  19.  
  20.         if (!empty($host) && !empty($user)) {
  21.             $this -> connect($host, $user, $pass);
  22.         }
  23.         if (!empty($database)) {
  24.             $this->select_database($database);
  25.         }
  26.         mysql_query("SET SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY'", $this->connection);
  27.     }
  28.  
  29.  
  30.     public function connect($host, $user, $pass = '') {
  31.         $this->connection = mysql_connect($host, $user, $pass);
  32.         if (!$this->connection) {
  33.             throw new Exception('could not connect to MYSQL Server');
  34.         }
  35.     }
  36.  
  37.     public function select_database($database_name) {
  38.         if (!empty($database_name)) {
  39.             if (empty($this->database)) {
  40.                 $this->database = $database_name;
  41.             }
  42.             if (!mysql_select_db($database_name, $this->connection)) {
  43.                 throw new Exception('Could not select database');
  44.             }
  45.         }
  46.     }
  47.  
  48.     public function execute($query) {
  49.         if (!mysql_query($query, $this->connection)) {
  50.             throw new Exception('could not execute the query', $query);
  51.         }
  52.         self::$executed_querys++;
  53.         return mysql_affected_rows($this->connection);
  54.     }
  55.  
  56.     public function query($query) {
  57.  
  58.         if (!$result = mysql_query($query, $this->connection)) {
  59.             throw new Exception("could not execute the query \n $query");
  60.         }
  61.  
  62.         self::$executed_querys++;
  63.         return new result($result);
  64.     }
  65.  
  66.     public function getTotalQuerys() {
  67.         return self::$executed_querys;
  68.     }
  69.  
  70.     public function __destruct() {
  71.         mysql_close($this->connection);
  72.     }
  73.  
  74.     public function getConnection() {
  75.         return $this->connection;
  76.     }
  77.  
  78.     public function getDatabase() {
  79.         return $this->database;
  80.     }
  81.  
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement