Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class database
- {
- var $db, $user, $pass, $host;
- private $dbconn, $table;
- function __construct ()
- {
- readconfig ('db');
- $this->db = $DB['db'];
- $this->user = $DB['user'];
- $this->pass = $DB['pass'];
- $this->host = $DB['host'];
- $this->table = 'users';
- $this->db_conn ();
- }
- function __destruct ()
- {
- mysql_close ($this->dbconn);
- }
- private function db_conn ()
- {
- $this->dbconn = mysql_connect ($this->host, $this->user, $this->pass)
- or die ('Error connecting to mysql host');
- mysql_select_db ($this->db, $this->dbconn)
- or die ('Error selecting database');
- }
- function set_table ($table)
- {
- $this->table = $table;
- }
- function query ($query)
- {
- return mysql_query ($this->parsequery ($query), $this->dbconn);
- }
- function parsequery ($query)
- {
- return mysql_real_escape_string ($query);
- }
- function simple_select ($what, $where = FALSE, $extra = "")
- {
- return $this->query ("SELECT {$what} FROM {$this->table}".($where)?' WHERE '.$where:''." {$extra}");
- }
- function simple_insert ($columns, $what, $extra = "")
- {
- return $this->query ("INSERT INTO {$this->table} ".(!$columns)?'':"({$columns})"." ({$what}) {$extra}");
- }
- function simple_update ($update, $where = FALSE, $extra = "")
- {
- $set = '';
- foreach ($update as $k => $v)
- $set .= $k." = '{$v}' ,";
- return $this->query ("UPDATE {$this->table} SET {$set} ".($where)?' WHERE '.$where:''." {$extra}");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement