Guest User

Untitled

a guest
Jan 13th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Simple general MySQL class
  4.  * Example usage:
  5.  * $mysql = new mysql();
  6.  * $mysql->query("SELECT * FROM users");
  7.  * $users = mysql->lastQuery();
  8.  */
  9. class mysql
  10. {
  11.     private $con;
  12.     private $query;
  13.     /*
  14.      * Constructor
  15.      * Connects to the mysql db by using the default values or the ones
  16.      * supplied while making an instance of this class
  17.      */
  18.    
  19.     function __construct($host="127.0.0.1", $user="root", $pass="pokemonwtf", $db="TSS")
  20.     {
  21.         $this->con = mysql_connect($host, $user, $pass);
  22.         if (!$this->con)
  23.         {
  24.             die('Could not connect: ' . mysql_error());
  25.         }
  26.         mysql_select_db($db, $this->con);
  27.     }
  28.     /*
  29.      * Does a simple MySQL query
  30.      */
  31.     function query($query)
  32.     {
  33.         $this->query = mysql_query($query, $this->con);
  34.     }
  35.     /*
  36.      * Returns the result of the last query
  37.      */
  38.     function lastQuery()
  39.     {
  40.         return $this->query;
  41.     }
  42.     /*
  43.      * Destructor
  44.      * Disconnects from the db
  45.      */
  46.     function __destruct()
  47.     {
  48.         mysql_close($con);
  49.     }
  50. }
  51. ?>
Add Comment
Please, Sign In to add comment