forked from fsmk/rasi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbConfig.php
executable file
·91 lines (81 loc) · 2.3 KB
/
dbConfig.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
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
85
86
87
88
89
90
91
<?php
class DBConfig {
var $host;
var $user;
var $pass;
var $db;
var $db_link;
var $conn = false;
var $persistant = false;
public $error = false;
public function config(){ // class config
$this->error = true;
$this->persistant = false;
}
function conn($host='localhost',$user='root',$pass='Mysql2012',$db='rasi'){ // connection function
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->db = $db;
if ($this->persistant)
$this->db_link = mysql_pconnect($this->host, $this->user, $this->pass, true);
else
$this->db_link = mysql_connect($this->host, $this->user, $this->pass, true);
if (!$this->db_link) {
if ($this->error) {
$this->error($type=1);
}
return false;
}
else {
if (empty($db)) {
if ($this->error) {
$this->error($type=2);
}
}
else {
$db = mysql_select_db($this->db, $this->db_link); // select db
if (!$db) {
if ($this->error) {
$this->error($type=2);
}
return false;
}
$this -> conn = true;
}
return $this->db_link;
}
}
function close() { // close connection
if ($this -> conn){ // check connection
if ($this->persistant) {
$this -> conn = false;
}
else {
mysql_close($this->db_link);
$this -> conn = false;
}
}
else {
if ($this->error) {
return $this->error($type=4);
}
}
}
public function error($type=''){ //Choose error type
if (empty($type)) {
return false;
}
else {
if ($type==1)
echo "<strong>Database could not connect</strong> ";
else if ($type==2)
echo "<strong>mysql error</strong> " . mysql_error();
else if ($type==3)
echo "<strong>error </strong>, Proses has been stopped";
else
echo "<strong>error </strong>, no connection !!!";
}
}
}
?>