Guest User

Untitled

a guest
Jan 13th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 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.     function __construct($host="127.0.0.1", $user="root", $pass="pokemonwtf", $db="TSS")
  19.     {
  20.         $this->con = mysql_connect($host, $user, $pass);
  21.         if (!$this->con)
  22.         {
  23.             die('Could not connect: ' . mysql_error());
  24.         }
  25.         mysql_select_db($db, $this->con);
  26.     }
  27.     /*
  28.      * Does a simple MySQL query
  29.      */
  30.     function query($query)
  31.     {
  32.         $this->query = mysql_query($query, $this->con);
  33.     }
  34.     /*
  35.      * Returns the result of the last query
  36.      */
  37.     function lastQuery()
  38.     {
  39.         return $this->query;
  40.     }
  41.     /*
  42.      * Destructor
  43.      * Disconnects from the db
  44.      */
  45.     function __destruct()
  46.     {
  47.         mysql_close($con);
  48.     }
  49. }
  50. ?>
Add Comment
Please, Sign In to add comment