Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Andre Liebich <[email protected]>
- * @copyright 2013 Browserforge
- * @link http://www.browserforge.com
- */
- class Mysql
- {
- private $host;
- private $username;
- private $password;
- private $database;
- /**
- * Create the Variable
- */
- function __construct()
- {
- $this -> host = "localhost"; // The Mysql-Host
- $this -> username = "localhost"; // The Username from Database
- $this -> password = "example"; // The Password from Database
- $this -> database = "test"; // Databasename
- Mysql::dbconnect();
- }
- /**
- * Create connection to Database
- */
- public function dbconnect()
- {
- $connection = mysql_connect($this->host, $this->username, $this->password) or die ("Account not found");
- mysql_select_db($this->database, $connection) or die ("Database not found.");
- }
- /**
- * Return the result of the Query like ("INSERT INTO `example`....")
- */
- public function query($query)
- {
- $query = mysql_query($query) or die (mysql_error());
- return $query;
- }
- /**
- * Return the result of the Query like ("SELECT * FROM `example` WHERE ......")
- */
- public function obj($query)
- {
- $query = mysql_fetch_object(mysql_query($query)) or die (mysql_error());
- return $query;
- }
- /**
- * Return a number of all results.
- */
- public function rows($query)
- {
- $query = mysql_num_rows(mysql_query($query)) or die (mysql_error());
- return $query;
- }
- /**
- * Returns an associative array with the field names as keys back
- */
- public function assoc($query)
- {
- $query = mysql_fetch_assoc(mysql_query($query)) or die (mysql_error());
- return $query;
- }
- /**
- * Return all results in a array
- */
- public function arry($query)
- {
- $query = mysql_fetch_array(mysql_query($query)) or die or die (mysql_error());
- return $query;
- }
- /**
- * Checks if a table exists
- * @param $table The Name of the Table
- */
- function table_exists($table)
- {
- if(mysql_query("SELECT * FROM `$table`")){
- return true;
- }else{
- return false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement