Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Database Class
- * Copyright Liam Symonds
- * Authored On: 8/05/2011
- */
- class Database {
- private static $_instance;
- public static $string;
- private $_username = "dbUser";
- private $_password = "dbPassword";
- private $_host = "dbHost";
- private $_database = "dbDB";
- private $_dbConnection;
- private $_dbSelection;
- private $_selection;
- private $_from;
- private $_where;
- private $_query;
- public static function Instance()
- {
- if( !isset( self::$_instance ) )
- {
- self::$_instance = new Database;
- }
- return self::$_instance;
- }
- private function __construct()
- {
- $this->_dbConnection = @mysql_connect( $this->_host, $this->_username, $this->_password );
- $this->_dbSelection = @mysql_select_db( $this->_database, $this->_dbConnection );
- }
- public function select( $string )
- {
- $this->_selection = $string;
- return $this;
- }
- public function from( $string )
- {
- $this->_from = $string;
- return $this;
- }
- public function where( $string )
- {
- $this->_where = $string;
- return $this;
- }
- public function query()
- {
- $this->_query = mysql_query( "SELECT {$this->_selection} FROM {$this->_from} {$this->_where}" );
- return $this->_query;
- }
- public static function escapeString( $string )
- {
- self::$string = mysql_real_escape_string( $string );
- return self::$string;
- }
- }
- $db = Database::Instance();
- ?>
Add Comment
Please, Sign In to add comment