-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.php
More file actions
84 lines (76 loc) · 2.19 KB
/
database.php
File metadata and controls
84 lines (76 loc) · 2.19 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
require_once("config.php");
class database{
protected $pdo = NULL;
protected $sql = '';
protected $sta = NULL;
public function __construct() {
try
{
$this->pdo = new PDO("mysql:host=".DB_HOST."; dbname=".DB_NAME,DB_USER,DB_PWD);
$this->pdo->query('set names "utf8"');
}
catch(PDOException $ex )
{
die($ex->getMessage());
}
}
public function setQuery($sql) {
$this->sql = $sql;
}
//Function execute the query
public function execute($options=array()) {
$this->sta = $this->pdo->prepare($this->sql);
if($options) { //If have $options then system will be tranmission parameters
for($i=0;$i<count($options);$i++) {
$this->sta->bindParam($i+1,$options[$i]);
}
}
$this->sta->execute();
return $this->sta;
}
//Funtion load datas on table
public function loadAllRows($options=array()) {
if(!$options) {
if(!$result = $this->execute())
return false;
}
else {
if(!$result = $this->execute($options))
return false;
}
return $result->fetchAll(PDO::FETCH_OBJ);
}
//Funtion load 1 data on the table
public function loadRow($option=array()) {
if(!$option) {
if(!$result = $this->execute())
return false;
}
else {
if(!$result = $this->execute($option))
return false;
}
return $result->fetch(PDO::FETCH_OBJ);
}
//Function count the record on the table
public function loadRecord($option=array()) {
if(!$option) {
if(!$result = $this->execute())
return false;
}
else {
if(!$result = $this->execute($option))
return false;
}
return $result->fetch(PDO::FETCH_COLUMN);
}
public function getLastId() {
return $this->pdo->lastInsertId();
}
public function disconnect() {
$this->sta=NULL;
$this->pdo = NULL;
}
}
?>