Kyberia v1.0
[mirrors/Kyberia-bloodline.git] / inc / database.inc
1 <?php
2
3 include_once ("result.inc");
4 include_once ("configdb.inc");
5
6 class CLASS_DATABASE {
7
8 var $Database=DB_DATABASE;
9 var $User=DB_USER;
10 var $Password=DB_PASS;
11 var $Url=DB_HOST;
12
13 var $_linkId = false;
14 var $_url = "";
15 var $_user = "";
16 var $_password = "";
17 var $_database = "kyberia";
18 var $_halt_on_error = true;
19 function CLASS_DATABASE () {
20 $this->connect("$this->Url","$this->User","$this->Password","$this->Database");
21 }
22
23 function connect($url, $user, $password, $database, $halt_on_error = true) {
24 $this->_halt_on_error = $halt_on_error;
25 if ($this->_linkId == false) {
26 $this->_linkId=mysql_connect($url, $user, $password);
27 if ($this->_linkId == false) {
28 $this->exception("weej databazka to nerozdychava ;)");
29 return false;
30 die();
31 }
32 $this->_url=$url;
33 $this->_user=$user;
34 $this->_password=$password;
35 if ($this->_linkId == false || mysql_select_db($database, $this->_linkId) == false) {
36 $this->exception("1Database failed.");
37 return false;
38 die();
39 }
40 $this->_database=$database;
41 }
42 return true;
43 }
44
45 function closeMysql() {
46 mysql_close($this->_linkId);
47 }
48
49 function query($sql) {
50 global $user_id;
51 if ($user_id==220 && $_GET['debug']) echo $sql;
52 $this->_queryId = mysql_db_query($this->_database,$sql,$this->_linkId);
53 if ($this->_queryId == false) {
54 $this->exception("query failed ::$sql::");
55 }
56
57 return new result($this->_queryId, $sql);
58 }
59
60
61 function executequery($sql) {
62 return($this->query($sql));
63 }
64
65 function executeupdate($sql) {
66 return($this->update($sql));
67 }
68
69 function update($sql) {
70
71 $this->_queryId = @mysql_db_query($this->_database,$sql,$this->_linkId);
72 if ($this->_queryId == false) {
73 $this->exception("update failed.");
74 }
75 $rows=@mysql_affected_rows($this->_linkId);
76 return($rows);
77 }
78
79 function getLastInsertId() {
80 return(@mysql_insert_id($this->_linkId));
81 }
82
83 function exception($errorMessage) {
84 echo "<!-- ";
85 echo @mysql_error($this->_linkId)," (",@mysql_errno($this->_linkId),")";
86 echo "-->";
87 if ($this->_halt_on_error) {
88 die("<pre>".$errorMessage."</pre>");
89 } else {
90 echo $errorMessage."<br>";
91 return false;
92 }
93 }
94 }
95 ?>
This page took 0.267748 seconds and 4 git commands to generate.