Advertisement
Guest User

Untitled

a guest
Aug 17th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. class database {
  2.  
  3.     var $link, $result;
  4.  
  5.     function database($host, $user, $pass, $db) {
  6.         $this->link = mysql_connect($host, $user, $pass) or $this->error();
  7.         mysql_select_db($db, $this->link) or $this->error();
  8.     }
  9.     function query($query) {
  10.         $this->result = mysql_query($query, $this->link) or $this->error();
  11.         $this->_query_count++;
  12.         return $this->result;
  13.     }
  14.     function countRows($result = "") {
  15.         if ( empty( $result ) )
  16.             $result = $this->result;
  17.         return mysql_num_rows($result);
  18.     }
  19.     function fetch($result = "") {
  20.         if ( empty( $result ) )
  21.             $result = $this->result;
  22.         return mysql_fetch_array($result);
  23.     }
  24.     function fetch_num($result = "") {
  25.         if ( empty( $result ) )
  26.             $result = $this->result;
  27.         return mysql_fetch_array($result, MYSQL_NUM);
  28.     }
  29.     function fetch_assoc($result = "") {
  30.         if ( empty( $result ) )
  31.             $result = $this->result;
  32.         return mysql_fetch_array($result, MYSQL_ASSOC);
  33.     }
  34.     function escape($str) {
  35.         return mysql_real_escape_string($str);
  36.     }
  37.     function error() {
  38.         if ( $_GET["debug"] == 0 ){
  39.             die(mysql_error());
  40.         } else {
  41.             echo "Error in db code";
  42.         }
  43.     }
  44. }
  45.  
  46. function sanitize($data) {
  47.     // apply stripslashes if magic_quotes_gpc is enabled
  48.     if(get_magic_quotes_gpc())
  49.         $data = stripslashes($data);
  50.  
  51.     // a mySQL connection is required before using this function
  52.     $data = trim(mysql_real_escape_string($data));
  53.  
  54.     return $data;
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement