Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- class MySQL
- {
- private static $connection = NULL;
- var $hostname = 'localhost';
- var $username = 'root';
- var $password = '';
- var $database = 'db_source';
- var $table = 'tbl_source';
- var $error_message = '';
- protected $is_ready = false;
- function __construct()
- {
- if( !$this->connect() || !$this->select_db() )
- {
- $this->set_error(__FUNCTION__);
- return;
- }
- $this->is_ready = true;
- }
- function set_error($message)
- {
- $this->error_message = $message;
- return false;
- }
- function is_ready()
- {
- return $this->is_ready;
- }
- function connect()
- {
- self::$connection = mysql_connect(
- empty($this->hostname) ? 'localhost' : $this->hostname,
- empty($this->username) ? 'root' : $this->username,
- empty($this->password) ? '' : $this->password
- );
- return $this->is_connected() ? true : $this->set_error(__FUNCTION__);
- }
- function select_db()
- {
- if( !$this->is_connected() )
- return $this->set_error(__FUNCTION__);
- return mysql_select_db($this->database, self::connection);
- }
- function is_connected()
- {
- return is_resource(self::connection) ? true : false;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment