Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Access_Class: Prototype MySQL handler with OOP Extensions
- *
- * @author XFlawless
- */
- class Access_Class {
- var $Server = 'localhost';
- var $Username = 'root';
- var $Password = '';
- var $Database = 'test';
- var $Connection;// Active connection variable.
- var $error_on = FALSE;// Keep this FALSE for saftey.
- // Please complete the above requirments.
- # Function: Connect, connects to the MySQL server.
- # Returns: Boolean
- public function Connect()
- {
- if(!$this->Connection)// Checks if the connection is alive.
- {
- $AHS_Con = mysql_connect($this->Server, $this->Username, $this->Password);
- $Connection = mysql_select_db($this->Database, $AHS_Con);
- if(!$AHS_Con && $error_on == TRUE)// Echo's the error if the connection is not available
- {
- echo 'Warning: Could not connect to mysql server'.time();
- return FALSE;
- }
- else
- {
- return $Connection;// If it's new connection this will return the connection ID
- }
- }
- else
- {
- return TRUE;// If the connection already exits then this will return TRUE boolean
- }
- }
- # Function: Disconnect(), closes the mysql server connection.
- # Return: closed connection boolean.
- public function Disconnect()
- {
- if(!$this->Connection && $this->error_on == TRUE)
- {
- echo 'Warning: No live MySQL connections were found';
- return FALSE;
- }
- else
- {
- return mysql_close();
- }
- }
- # Function: Query(), executes the input query in a safe way.
- # Returns: Query output in a array.
- public function Query($string)
- {
- if(!$this->Connection && $this->error_on == TRUE)
- {
- echo '</br>Warning: Query could not be executed.</br></br>Reason: No Active MySQL connections found.</br>';
- return FALSE;
- }
- else
- {
- $_AHS_Q = mysql_query($string);
- if(!$_AHS_Q)
- {
- echo '</br>Could not execute the mysql query.</br>';
- return FALSE;
- }
- else
- {
- return $_AHS_Q;
- }
- }
- }
- # Function: Santize(), Cleans the input characters and escapes unwanted characters.
- # Returns: Filtered string.
- public function Santize($text)
- {
- $text = stripslashes($text);
- $text = htmlentities($text);
- $text = mysql_real_escape_string($text);
- return $text;
- }
- # Function: Optimize(), Optimizes the table which is given.
- # Return: Echo's mysql affected rows if needed.
- public function Optimize($tablename)
- {
- if(!$this->Connection && $this->error_on == TRUE)
- {
- echo 'Warning: Could not optimize the table !</br></br>Reason: No Active MySQL connections found.';
- return FALSE;
- }
- else
- {
- $_AHS_QO = mysql_query("OPTIMIZE TABLE '".$tablename."'");
- if($_AHS_QO == 0)
- {
- return mysql_error();
- }
- else
- {
- return mysql_affected_rows();
- }
- }
- }
- # Function: Repair(), Repairs the table which is given.
- # Return: Echo's mysql affected rows if needed.
- public function Repair($tablename)
- {
- if(!$this->Connection && $this->error_on == TRUE)
- {
- echo 'Warning: Could not optimize the table !</br></br>Reason: No Active MySQL connections found.';
- return FALSE;
- }
- else
- {
- $_AHS_QO = mysql_query("REPAIR TABLE '".$tablename."'");
- if($_AHS_QO == 0)
- {
- return mysql_error();
- }
- else
- {
- echo mysql_affected_rows();
- return TRUE;
- }
- }
- }
- # Function: S_Hash($string), this will hash the input text with whirlpool and md5.
- # Return: Hashed String.
- public function S_Hash($string)
- {
- self::Santize($string);
- $Salt = md5($string);
- $Salt2 = hash('whirlpool', $Salt);
- return $Salt2;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement