Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.78 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Serenity
  5.  * Date: 6-okt-2010
  6.  * Time: 19:15:32
  7.  * To change this template use File | Settings | File Templates.
  8.  */
  9.  
  10. class Mysql {
  11.  
  12.     private $connection;
  13.     private $database;
  14.  
  15.     private static $executed_querys;
  16.  
  17.     public function __construct($host = '', $user = '', $pass = '', $database = '') {
  18.       echo $pass;
  19.         if (!empty($host) && !empty($user)) {
  20.             $this -> connect($host, $user, $pass);
  21.  
  22.         }
  23.         if (!empty($database)) {
  24.             $this->select_database($database);
  25.         }
  26.          if (!empty($host) && !empty($user) && !empty($database)) {
  27.           mysql_query("SET SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY'", $this->connection);
  28.          }
  29.  
  30.     }
  31.  
  32.     public function connect($host, $user, $pass = '') {
  33.         $this->connection = mysql_connect($host, $user, $pass);
  34.         if (!$this->connection) {
  35.             throw new Exception('could not connect to MYSQL Server');
  36.         }
  37.     }
  38.  
  39.     public function select_database($database_name) {
  40.         if (!empty($database_name)) {
  41.             if (empty($this->database)) {
  42.                 $this->database = $database_name;
  43.             }
  44.             if (!mysql_select_db($database_name, $this->connection)) {
  45.                 throw new Exception('Could not select database');
  46.             }
  47.         }
  48.     }
  49.  
  50.     public function execute($query) {
  51.         if (!mysql_query($query, $this->connection)) {
  52.             throw new Exception("could not execute the query :\n<br>\n<br>$query \n<br>\n<br>");
  53.         }
  54.         self::$executed_querys++;
  55.         return mysql_affected_rows($this->connection);
  56.     }
  57.  
  58.     public function query($query) {
  59.  
  60.         if (!$result = mysql_query($query, $this->connection)) {
  61.             throw new Exception("could not execute the query :\n<br>\n<br> $query\n<br>\n<br>");
  62.         }
  63.  
  64.         self::$executed_querys++;
  65.         return new mysql_result($result);
  66.     }
  67.  
  68.     public function getTotalQuerys() {
  69.         return self::$executed_querys;
  70.     }
  71.  
  72.     public function __destruct() {
  73.      //   mysql_close($this->connection);
  74.     }
  75.  
  76.     public function disconnect(){
  77.       // $this->__destruct();
  78.     }
  79.  
  80.     public function getConnection() {
  81.         return $this->connection;
  82.     }
  83.  
  84.     public function getDatabase() {
  85.         return $this->database;
  86.     }
  87. }
  88.  
  89.  
  90. ======================================================================================================================================
  91.  
  92. <?php
  93. /**
  94.  * Created by PhpStorm.
  95.  * User: Serenity
  96.  * Date: 6-okt-2010
  97.  * Time: 19:15:41
  98.  * To change this template use File | Settings | File Templates.
  99.  */
  100.  
  101. class mysql_result {
  102.     private $result;
  103.  
  104.     private $last_row;
  105.     private $rowset;
  106.  
  107.  
  108.     public function __construct($result) {
  109.         if (!is_resource($result)) {
  110.             throw new Exception('$result is not a valid resource');
  111.         }
  112.         $this->result = $result;
  113.     }
  114.  
  115.     public function fetch() {
  116.         $this->last_row = mysql_fetch_assoc($this->result);
  117.         return $this->last_row;
  118.     }
  119.  
  120.     public function next(){
  121.         $this->fetch();
  122.     }
  123.  
  124.     public function getRow(){
  125.         return $this->last_row;
  126.     }
  127.  
  128.     public function fetchField($field) {
  129.         if (!is_array($this -> last_row))
  130.             $this -> fetch();
  131.         return strip_tags(stripslashes($this->last_row[$field]));
  132.     }
  133.  
  134.     public function valid() {
  135.         return $this -> current() != false;
  136.     }
  137.  
  138.     public function current() {
  139.         if (!is_array($this -> last_row))
  140.             $this -> fetch();
  141.         return $this -> last_row;
  142.     }
  143.  
  144.     public function seek($id){
  145.        if(!mysql_data_seek($this->result,$id))
  146.       throw new Exception('invalid row');
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement