Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2. class Database
  3. {
  4.     function Database($servername, $username, $password, $dbname)
  5.     {
  6.         $this->servername = $servername;
  7.         $this->username = $username;
  8.         $this->password = $password;
  9.         $this->dbname = $dbname;
  10.     }
  11.     function connect()
  12.     {
  13.         $con = mysql_connect($this->servername, $this->username, $this->password);
  14.         if (!$con)
  15.         {
  16.             die('Could not connect: ' . mysql_error());
  17.         }
  18.         mysql_select_db($this->dbname, $con) or die ('Could not select db');
  19.         return true;
  20.     }
  21.  
  22.     function query($query)
  23.     {
  24.         $result = mysql_query($query) or die('Could not execute the query: '.$query.' <br/>Error:'  . mysql_error( )  );
  25.         return $result;
  26.     }
  27.  
  28.     function protect($variable)
  29.     {
  30.       $var2 = $variable;
  31.       $var2 = htmlspecialchars(mysql_real_escape_string($var2));
  32.       return $var2;
  33.     }
  34.  
  35. }
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement