Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class engine
- {
- private $hostname;
- private $username;
- private $password;
- private $database;
- public $connected;
- private $functions = array(
- 'connect' => '@mysql_connect',
- 'select_db' => '@mysql_select_db',
- 'close' => '@mysql_close',
- 'query' => '@mysql_query',
- 'escape_string' => '@mysql_real_escape_string',
- 'num_rows' => '@mysql_num_rows',
- 'result' => '@mysql_result',
- 'fetch_assoc' => '@mysql_fetch_assoc',
- 'fetch_array' => '@mysql_fetch_array'
- );
- private $fetchT = array(
- 'both' => '@MYSQL_BOTH',
- 'assoc' => '@MYSQL_ASSOC'
- );
- public function __construct($hostname, $username, $password, $database)
- {
- $this->hostname = $hostname;
- $this->username = $username;
- $this->password = $password;
- $this->password = $password;
- }
- final public function connect()
- {
- if(!$this->connected)
- {
- $myconnection = $this->functions['connect']($this->hostname, $this->username, $this->password);
- if($myconnection)
- {
- $mydatabase = $this->functions['select_db']($this->database);
- if($mydatabase)
- {
- $this->connected = true;
- return true;
- }
- else
- {
- //Couldn't connect to database
- }
- }
- else
- {
- //Couldn't connect to host
- }
- }
- else
- {
- return true;
- }
- }
- final public function disconnect()
- {
- if($this->connected)
- {
- if($this->functions['close'])
- {
- $this->connection = false;
- return true;
- }
- else
- {
- //Couldn't disconnect
- }
- }
- }
- final public function secure($var)
- {
- return $this->function['escape_string'](stripslashes(htmlspecialchars($var)));
- }
- final public function select($table, $rows, $where = null, $order = null, $reason)//$engine->select('users','*','id='.$id,null,fetch_assoc)
- {
- if($this->connected)
- {
- $select = "SELECT " . $rows . " FROM " . $table;
- if($where != null)
- {
- $select .= " WHERE " . $where;
- if($order != null)
- {
- $select .= " ORDER BY" . $order;
- }
- }
- $select = $this->functions['query']($select);
- if($select)
- {
- if($reason)
- {
- switch($reason)
- {
- case 'num_rows':
- return $this->functions['num_rows']($select) or die(mysql_error());
- break;
- case 'fetch_assoc':
- return $this->functions['fetch_assoc']($select, $this->fetchT['both']) or die(mysql_error());
- break;
- case 'fetch_array':
- return $this->functions['fetch_array']($select, $this->fetchT['assoc']) or die(mysql_error());
- break;
- default:
- return false;
- break;
- }
- }
- else
- {
- //No reason specified must have a reason
- }
- }
- }
- }
- final public function update($table, $row, $where = null)
- {
- if($this->connected)
- {
- $update = "UPDATE " . $table . " SET " . $row;
- if($where != null)
- {
- $update .= "WHERE" . $where;
- }
- return $this->functions['query']($update) or die(mysql_error());
- }
- }
- final public function insert($table, $rows = null, $values)
- {
- if($this->connected)
- {
- $insert = "INSERT INTO" . $table;
- if($rows != null)
- {
- $insert .= "(" . $rows . ") VALUES(" . $values . ")";
- }
- return $this->functions['query']($insert) or die(mysql_error());
- }
- }
- final public function delete($table, $where = null)
- {
- if($this->connected)
- {
- if($where != null)
- {
- $delete = "DELETE FROM " . $table . " WHERE " . $where;
- }
- else
- {
- $delete = "DELETE " . $table;
- }
- return $this->functions['query']($delete);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment