Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.39 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Access_Class: Prototype MySQL handler with OOP Extensions
  4.  *
  5.  * @author XFlawless
  6.  */
  7. class Access_Class {
  8.     var $Server   = 'localhost';
  9.     var $Username = 'root';
  10.     var $Password = '';
  11.     var $Database = 'test';
  12.     var $Connection;// Active connection variable.
  13.     var $error_on = FALSE;// Keep this FALSE for saftey.
  14.     // Please complete the above requirments.
  15.    
  16.     # Function: Connect, connects to the MySQL server.
  17.    # Returns: Boolean
  18.    public function Connect()
  19.     {
  20.         if(!$this->Connection)// Checks if the connection is alive.
  21.         {
  22.             $AHS_Con = mysql_connect($this->Server, $this->Username, $this->Password);
  23.             $Connection = mysql_select_db($this->Database, $AHS_Con);
  24.             if(!$AHS_Con && $error_on == TRUE)// Echo's the error if the connection is not available
  25.             {
  26.                 echo 'Warning: Could not connect to mysql server'.time();
  27.                 return FALSE;
  28.             }
  29.             else
  30.             {
  31.                 return $Connection;// If it's new connection this will return the connection ID
  32.             }
  33.         }
  34.         else
  35.         {
  36.             return TRUE;// If the connection already exits then this will return TRUE boolean
  37.         }
  38.     }
  39.     # Function: Disconnect(), closes the mysql server connection.
  40.    # Return: closed connection boolean.
  41.    public function Disconnect()
  42.     {
  43.         if(!$this->Connection && $this->error_on == TRUE)
  44.         {
  45.             echo 'Warning: No live MySQL connections were found';
  46.             return FALSE;
  47.         }
  48.         else
  49.         {
  50.             return mysql_close();
  51.         }
  52.        
  53.     }
  54.    
  55.     # Function: Query(), executes the input query in a safe way.
  56.    # Returns: Query output in a array.
  57.    public function Query($string)
  58.     {
  59.         if(!$this->Connection && $this->error_on == TRUE)
  60.         {
  61.             echo '</br>Warning: Query could not be executed.</br></br>Reason: No Active MySQL connections found.</br>';
  62.             return FALSE;
  63.         }
  64.         else
  65.         {
  66.             $_AHS_Q = mysql_query($string);
  67.             if(!$_AHS_Q)
  68.             {
  69.                 echo '</br>Could not execute the mysql query.</br>';
  70.                 return FALSE;
  71.             }
  72.             else
  73.             {
  74.                 return $_AHS_Q;
  75.             }
  76.         }
  77.     }
  78.    
  79.     # Function: Santize(), Cleans the input characters and escapes unwanted characters.
  80.    # Returns: Filtered string.
  81.    public function Santize($text)
  82.     {
  83.         $text = stripslashes($text);
  84.         $text = htmlentities($text);
  85.         $text = mysql_real_escape_string($text);
  86.         return $text;
  87.     }
  88.    
  89.     # Function: Optimize(), Optimizes the table which is given.
  90.    # Return: Echo's mysql affected rows if needed.
  91.    public function Optimize($tablename)
  92.     {
  93.         if(!$this->Connection && $this->error_on == TRUE)
  94.         {
  95.             echo 'Warning: Could not optimize the table !</br></br>Reason: No Active MySQL connections found.';
  96.             return FALSE;
  97.         }
  98.         else
  99.         {
  100.             $_AHS_QO = mysql_query("OPTIMIZE TABLE '".$tablename."'");
  101.             if($_AHS_QO == 0)
  102.             {
  103.                 return mysql_error();
  104.             }
  105.             else
  106.             {
  107.                 return mysql_affected_rows();
  108.             }
  109.         }  
  110.     }
  111.    
  112.     # Function: Repair(), Repairs the table which is given.
  113.    # Return: Echo's mysql affected rows if needed.
  114.    public function Repair($tablename)
  115.     {
  116.         if(!$this->Connection && $this->error_on == TRUE)
  117.         {
  118.             echo 'Warning: Could not optimize the table !</br></br>Reason: No Active MySQL connections found.';
  119.             return FALSE;
  120.         }
  121.         else
  122.         {
  123.             $_AHS_QO = mysql_query("REPAIR TABLE '".$tablename."'");
  124.             if($_AHS_QO == 0)
  125.             {
  126.                 return mysql_error();
  127.             }
  128.             else
  129.             {
  130.                 echo mysql_affected_rows();
  131.                 return TRUE;
  132.             }
  133.         }  
  134.     }
  135.    
  136.     # Function: S_Hash($string), this will hash the input text with whirlpool and md5.
  137.    # Return: Hashed String.
  138.    public function S_Hash($string)
  139.     {
  140.         self::Santize($string);
  141.         $Salt = md5($string);
  142.         $Salt2 = hash('whirlpool', $Salt);
  143.         return $Salt2;
  144.     }
  145. }
  146.  
  147. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement