Advertisement
Guest User

Untitled

a guest
May 18th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2. class Database{
  3.  
  4.   public $dbLink;
  5.   public $queryID;
  6.   public $record;
  7.   public $host;
  8.   public $database;
  9.   public $user;
  10.   public $password;
  11.   public $charsetID;
  12.  
  13.   function Database($host="x", $db="x", $user="x", $pwd="x"){
  14.     $this->host = $host;
  15.     $this->database = $db;
  16.     $this->user = $user;
  17.     $this->password = $pwd;
  18.     $this->connect();
  19.   }
  20.  
  21.   function connect() {
  22.     $this->dbLink = mysqli_connect($this->host, $this->user, $this->password, $this->database);
  23.     if (mysqli_connect_errno()) {
  24.            printf("Connect failed: %s\n", mysqli_connect_error());
  25.            exit();
  26.         }
  27.         if(!$this->dbLink) {
  28.       exit;
  29.     } else {
  30.         $s = "SET NAMES 'utf8'";
  31.         $this->charsetID = $this->query($s);
  32.     }
  33.   }
  34.  
  35.   function query($sql) {
  36.     if(empty($this->dbLink))
  37.       $this->connect();
  38.     $this->queryID = mysqli_query($this->dbLink,$sql);
  39.    
  40.     if(!$this->queryID) {
  41.       return(false);
  42.       exit;
  43.     } else return(true);
  44.   }  
  45.  
  46.   function nextRecord() {
  47.     if ($this->queryID) {
  48.         $this->record = mysqli_fetch_array($this->queryID);
  49.         $status = is_array($this->record);
  50.         return($status);
  51.       } else return(false);
  52.   }
  53.  
  54.   function numRows() {
  55.     $rows = mysqli_num_rows($this->queryID);
  56.     return($rows);
  57.   }
  58.  
  59.   function getField($field) {
  60.     return($this->record[$field]);
  61.   }
  62.  
  63.   function lastID() {
  64.     return mysqli_insert_id($this->dbLink);
  65.   }
  66.  
  67.   function close() {
  68.     mysqli_close($this->dbLink);
  69.   }
  70.  
  71. }
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement