Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Simple MySQL class
- // Created by Bipshark
- // E-mail: faz@live.se
- // This comment should not be removed
- class mysql
- {
- public $_host;
- public $_user;
- public $_pass;
- public $_db;
- public $_result;
- public $_sql;
- public $_query;
- public $_link;
- public function __construct($_host = '', $_user = '', $_pass = '', $_db = '')
- {
- return $this->connect($_host, $_user, $_pass, $_db);
- }
- public function __desctruct()
- {
- if(isset($this->_query)) { mysql_free_result($this->_query); }
- return mysql_close($this->_link);
- }
- public function connect($_host, $_user, $_pass, $_db)
- {
- $this->_host = $_host;
- $this->_user = $_user;
- $this->_pass = $_pass;
- $this->_db = $_db;
- $this->_link = mysql_connect($this->_host, $this->_user, $this->_pass) or die(mysql_error());
- if($this->_db)
- {
- $this->select_database($this->_db) or die(mysql_error());
- }
- return $this->_link;
- }
- function select_database($_db)
- {
- $this->_db = $_db;
- return mysql_select_db($_db) or die(mysql_error());
- }
- public function query($_query)
- {
- $args = func_get_args();
- $this->_sql = $_query;
- array_shift($args);
- if(count($args) > 0)
- {
- foreach($args as $key => $value)
- {
- $replace = ((is_float($value)) ? mysql_real_escape_string($value) : "'" . mysql_real_escape_string($value) . "'");
- $this->_sql = str_replace('%' . ++$key, $replace, $this->_sql);
- }
- }
- $this->_query = mysql_query($this->_sql, $this->_link) or die(mysql_error());
- return $this->_query;
- }
- public function fetch($_query = '', $type = 'assoc')
- {
- $_query = ((empty($_query)) ? $this->_query : $_query);
- $this->_result = ((strtolower($type) == 'assoc') ? mysql_fetch_assoc($_query) : mysql_fetch_row($_query));
- return $this->_result;
- }
- public function num_rows($_query = '')
- {
- $_query = ((empty($_query)) ? $this->_query : $_query);
- return mysql_num_rows($_query);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment