Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database{
- public $dbLink;
- public $queryID;
- public $record;
- public $host;
- public $database;
- public $user;
- public $password;
- public $charsetID;
- function Database($host="x", $db="x", $user="x", $pwd="x"){
- $this->host = $host;
- $this->database = $db;
- $this->user = $user;
- $this->password = $pwd;
- $this->connect();
- }
- function connect() {
- $this->dbLink = mysqli_connect($this->host, $this->user, $this->password, $this->database);
- if (mysqli_connect_errno()) {
- printf("Connect failed: %s\n", mysqli_connect_error());
- exit();
- }
- if(!$this->dbLink) {
- exit;
- } else {
- $s = "SET NAMES 'utf8'";
- $this->charsetID = $this->query($s);
- }
- }
- function query($sql) {
- if(empty($this->dbLink))
- $this->connect();
- $this->queryID = mysqli_query($this->dbLink,$sql);
- if(!$this->queryID) {
- return(false);
- exit;
- } else return(true);
- }
- function nextRecord() {
- if ($this->queryID) {
- $this->record = mysqli_fetch_array($this->queryID);
- $status = is_array($this->record);
- return($status);
- } else return(false);
- }
- function numRows() {
- $rows = mysqli_num_rows($this->queryID);
- return($rows);
- }
- function getField($field) {
- return($this->record[$field]);
- }
- function lastID() {
- return mysqli_insert_id($this->dbLink);
- }
- function close() {
- mysqli_close($this->dbLink);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement