-
Notifications
You must be signed in to change notification settings - Fork 0
/
class_db.php
50 lines (47 loc) · 1.22 KB
/
class_db.php
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
<?php
class database
{
private $con;
public $host = "localhost";
public $user = "root";
public $passwd = "";
public $db = "database2";
function __construct(){
$this->start_con();
}
function start_con(){
if(!$this->con = new mysqli($this->host,$this->user,$this->passwd, $this->db))
die('Can not connect mysql server local');
}
function close_con(){
return mysqli_close($this->con);
}
function sqlquery($sql){
if(!$this->con = new mysqli($this->host,$this->user,$this->passwd, $this->db))
die('Can not connect mysql server');
return $this->con->query($sql);
}
function jumrec($sql){ //jumlah hasil
if($hasil=$this->sqlquery($sql))
//$jum=$hasil->num_rows;
$jum = mysqli_num_rows($hasil);
else
$jum=0;
return $jum;
}
function datasql($sql){
$data = array();
if($hasil=$this->sqlquery($sql))
$data=$hasil->fetch_array(MYSQLI_BOTH);
return $data;
}
function fetchdata($sql){
$res = array();
if($hasil=$this->sqlquery($sql))
while($data=$hasil->fetch_array(MYSQLI_BOTH)){
$res[] = $data;
}
return $res;
}
}
?>