-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb.php
More file actions
67 lines (60 loc) · 2.13 KB
/
Copy pathdb.php
File metadata and controls
67 lines (60 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
class DB{
protected $mysqli;
protected $result;
protected $row=array();
public function __construct($host,$user,$passwd,$database){
$this->mysqli=new mysqli($host,$user,$passwd,$database);
if($this->mysqli->errno){
die('Connection Error:'.$this->mysqli->error);
}else{
$this->mysqli->set_charset('UTF8');
}
}
public function get_rows_array($sql){//fetch all the associated sets
if(!empty($this->row)){
$this->close();
}
$this->result=$this->mysqli->query($sql);
if($this->result && $this->result->num_rows>0){
$row=array();
while($rows=$this->result->fetch_assoc()){
$this->row[]=$rows;
}
}
return $this->row;
}
public function fetch_one_array($sql){//fetch one single set
if(!empty($this->row)){
$this->close();
}
$this->result=$this->mysqli->query($sql);
if($this->result && $this->result->num_rows>0){
$this->row=$this->result->fetch_assoc();
}
return $this->row;
}
public function get_total_num($sql){//get the total number of one of your table
if(!empty($this->row)){
$this->close();
}
$this->result=$this->mysqli->query($sql);
if($this->result && $this->result->num_rows>0){
$this->row=$this->result->fetch_array();
}
return $this->row[0];
}
public function getAffectedRows(){
return $this->mysqli->affected_rows;
}
protected function close(){
$this->row=array();
}
public function __destruct(){
$this->result->free();
$this->mysqli->close();
}
}
require_once 'config.php';//this is your config file which contains your mysql username,password,port and database name
$DB=new DB($host,$user,$passwd,$database);
?>