Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 53 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. <?php
  2. require_once("config.php");
  3.  
  4. //echo DB_SERVER . "<br />" . DB_USER . "<br />" . DB_PASS . "<br />" . DB_NAME . "<br />";
  5.  
  6. class MySQLDatabase {
  7.  
  8.     private $connection;
  9.  
  10.     function __construct() {
  11.         $this->open_connection();
  12.     }
  13.  
  14.     // create connection to database and select it
  15.     public function open_connection() {
  16.         $this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
  17.         if(!$this->connection) {
  18.             die("Database connection failed: " . mysqli_error());
  19.         }   else{
  20.                 $db_selected = mysqli_select_db($this->connection, DB_NAME);
  21.                 if (!$db_selected) {
  22.                     die("Database selection failed: " . mysqli_error());
  23.                 }
  24.             }
  25.     }
  26.  
  27.     // close database connection
  28.     public function close_connection() {
  29.         if(isset($this->connection)){
  30.             mysqli_close($this->connection);
  31.             unset($this->connection);
  32.         }
  33.     }
  34.  
  35.  
  36.     // perform query
  37.     public function query($sql){
  38.         $result = mysqli_query($this->connection, $sql);
  39.         $this->confirm_query($result);
  40.         return $result;
  41.     }
  42.  
  43.  
  44.     // prep data for submission to mysql
  45.     public function mysql_prep( $value ) {
  46.         $magic_quotes_active = get_magic_quotes_gpc();
  47.         $new_enough_php = function_exists( "mysqli_real_escape_string" ); // i.e. PHP >= v4.3.0
  48.         if( $new_enough_php ) { // PHP v4.3.0 or higher
  49.             // undo any magic quote effects so mysql_real_escape_string can do the work
  50.             if( $magic_quotes_active ) { $value = stripslashes( $value ); }
  51.             $value = mysqli_real_escape_string( $value );
  52.         } else { // before PHP v4.3.0
  53.             // if magic quotes aren't already on then add slashes manually
  54.             if( !$magic_quotes_active ) { $value = addslashes( $value ); }
  55.             // if magic quotes are active, then the slashes already exist
  56.         }
  57.         return $value;
  58.         }
  59.  
  60.  
  61.     // confirm query success
  62.     private function confirm_query($result) {
  63.         if (!$result) {
  64.             die("Database query failed: " . mysqli_error());
  65.         }
  66.     }
  67.  
  68.  
  69. }
  70.  
  71. $database = new MySQLDatabase();
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