irwan

PHP BASIC (Database class)

Feb 15th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1.     <?
  2.     class MySql {
  3.     public function query($sql){
  4.     $query = @mysql_query($sql, $this->handle) or die(mysql_errno().": ".mysql_error());
  5.     return new Result($query);
  6.     }
  7.      
  8.     public function connect($host, $root, $pass, $data){
  9.     $connect = @mysql_connect($host, $root, $pass) or die(mysql_errno().": ".mysql_error());
  10.     @mysql_select_db($data, $connect) or die(mysql_errno().": ".mysql_error());
  11.     $this->handle = $connect;
  12.     return $connect;
  13.     }
  14.      
  15.     public function put($str){
  16.     return new Text($str);
  17.     }
  18.      
  19.     public function last(){
  20.     return @mysql_insert_id($this->handle);
  21.     }
  22.      
  23.     public function close(){
  24.     return @mysql_close($this->handle);
  25.     }
  26.     }
  27.      
  28.     class Result extends MySql{
  29.     public function Result($result){
  30.     $this->query = $result;
  31.     }
  32.      
  33.     public function fetch(){
  34.     return @mysql_fetch_array($this->query);
  35.     }
  36.      
  37.     public function is(){
  38.     return ($this->query?true:false);
  39.     }
  40.      
  41.     public function cell($num=0){
  42.     $row = @mysql_fetch_row($this->query);
  43.     return $row[$num];
  44.     }
  45.      
  46.     public function num(){
  47.     return @mysql_num_rows($this->query);
  48.     }
  49.      
  50.     public function finish(){
  51.     return $this->query;
  52.     }
  53.     }
  54.      
  55.     class Text extends MySql{
  56.     public function Text($text){
  57.     $this->text = $text;
  58.     }
  59.      
  60.     public function hash(){
  61.     return sha1($this->text);
  62.     }
  63.      
  64.     public function protect(){
  65.     if(get_magic_quotes_runtime()){
  66.     $this->text = htmlspecialchars(stripslashes($this->text));
  67.     }
  68.      
  69.     return @mysql_real_escape_string($this->text);
  70.     }
  71.     }
  72.     ?>
Advertisement
Add Comment
Please, Sign In to add comment