Advertisement
Guest User

Untitled

a guest
May 7th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php
  2.  
  3.   class database
  4.   {
  5.  
  6.     var $db, $user, $pass, $host;
  7.     private $dbconn, $table;
  8.  
  9.     function __construct ()
  10.     {
  11.       readconfig ('db');
  12.       $this->db = $DB['db'];
  13.       $this->user = $DB['user'];
  14.       $this->pass = $DB['pass'];
  15.       $this->host = $DB['host'];
  16.       $this->table = 'users';
  17.       $this->db_conn ();
  18.     }
  19.  
  20.     function __destruct ()
  21.     {
  22.       mysql_close ($this->dbconn);
  23.     }
  24.  
  25.     private function db_conn ()
  26.     {
  27.       $this->dbconn = mysql_connect ($this->host, $this->user, $this->pass)
  28.         or die ('Error connecting to mysql host');
  29.       mysql_select_db ($this->db, $this->dbconn)
  30.         or die ('Error selecting database');
  31.     }
  32.  
  33.     function set_table ($table)
  34.     {
  35.       $this->table = $table;
  36.     }
  37.  
  38.     function query ($query)
  39.     {
  40.       return mysql_query ($this->parsequery ($query), $this->dbconn);
  41.     }
  42.  
  43.     function parsequery ($query)
  44.     {
  45.       return mysql_real_escape_string ($query);
  46.     }
  47.  
  48.     function simple_select ($what, $where = FALSE, $extra = "")
  49.     {
  50.       return $this->query ("SELECT  {$what} FROM {$this->table}".($where)?' WHERE '.$where:''." {$extra}");
  51.     }
  52.  
  53.     function simple_insert ($columns, $what, $extra = "")
  54.     {
  55.       return $this->query ("INSERT INTO {$this->table} ".(!$columns)?'':"({$columns})"." ({$what}) {$extra}");
  56.     }
  57.  
  58.     function simple_update ($update, $where = FALSE, $extra = "")
  59.     {
  60.       $set = '';
  61.       foreach ($update as $k => $v)
  62.         $set .= $k." = '{$v}' ,";
  63.       return $this->query ("UPDATE {$this->table} SET {$set} ".($where)?' WHERE '.$where:''." {$extra}");
  64.     }
  65.  
  66.   }
  67.  
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement