daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Apr 27th, 2018 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Usage Example:
  4. $db = new Connection('MySite');
  5. $result = $db->query("select * from Table where someField='%s' and someOtherField='%s'", array($value1, $value2));
  6. From here on you just handle $result like a normal response from a mysql_query().
  7. */
  8.  
  9. if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){header('Location: index.php');} //makes this file include-only by checking if the requested file is the same as this file
  10.  
  11. class Connection
  12. {
  13.     protected $connection;
  14.     #default values
  15.    private $server="localhost", $username="root", $password="", $database="pentest";
  16.  
  17.     function __construct()
  18.     {
  19.         $a = func_get_args();
  20.         $i = func_num_args();
  21.         if (method_exists($this,$f='__construct'.$i)) {
  22.             call_user_func_array(array($this,$f),$a);
  23.         }
  24.     }
  25.  
  26.     public function __construct1($database)
  27.     {
  28.         $this->database = $database;
  29.         $this->connect();
  30.     }
  31.  
  32.     public function __construct4($server, $username, $password, $database)
  33.     {
  34.         $this->server = $server;
  35.         $this->username = $username;
  36.         $this->password = $password;
  37.         $this->database = $database;
  38.         $this->connect();
  39.     }
  40.  
  41.     private function connect()
  42.     {
  43.         $this->connection = mysql_connect($this->server, $this->username, $this->password);
  44.         mysql_select_db($this->database, $this->connection);
  45.     }
  46.  
  47.     public function sanitize($formatString, array $args)
  48.     {
  49.         $len = count($args);
  50.         for($arg=0; $arg < $len; $arg++)
  51.         {
  52.             $args[$arg] = mysql_real_escape_string($args[$arg]);
  53.         }
  54.         return vsprintf($formatString, $args);
  55.     }
  56.  
  57.     public function query($formatString, array $args)
  58.     {
  59.         $q = $this->sanitize($formatString, $args);
  60.         $result = mysql_query($q);
  61.         return $result;
  62.     }
  63.     public function close()
  64.     {
  65.         mysql_close($this->connection);
  66.     }
  67. }
  68. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top