Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Simple general MySQL class
- * Example usage:
- * $mysql = new mysql();
- * $mysql->query("SELECT * FROM users");
- * $users = mysql->lastQuery();
- */
- class mysql
- {
- private $con;
- private $query;
- /*
- * Constructor
- * Connects to the mysql db by using the default values or the ones
- * supplied while making an instance of this class
- */
- function __construct($host="127.0.0.1", $user="root", $pass="pokemonwtf", $db="TSS")
- {
- $this->con = mysql_connect($host, $user, $pass);
- if (!$this->con)
- {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db($db, $this->con);
- }
- /*
- * Does a simple MySQL query
- */
- function query($query)
- {
- $this->query = mysql_query($query, $this->con);
- }
- /*
- * Returns the result of the last query
- */
- function lastQuery()
- {
- return $this->query;
- }
- /*
- * Destructor
- * Disconnects from the db
- */
- function __destruct()
- {
- mysql_close($con);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment