Kyberia v2.0
[mirrors/Kyberia-bloodline.git] / inc / database.inc
1 <?php
2 /* This program is free software. It comes without any warranty, to
3 * the extent permitted by applicable law. You can redistribute it
4 * and/or modify it under the terms of the Do What The Fuck You Want
5 * To Public License, Version 2, as published by Sam Hocevar. See
6 * http://sam.zoy.org/wtfpl/COPYING for more details. */
7
8 require ("result.inc");
9
10 class CLASS_DATABASE {
11
12 var $Database="";
13 var $User="";
14 var $Password="";
15 var $Url="";
16
17 var $_linkId = false;
18 var $_url = "";
19 var $_user = "";
20 var $_password = "";
21 var $_database = "";
22 var $_halt_on_error = true;
23
24 function CLASS_DATABASE ($database=DB_DATABASE,$user=DB_USER,$password=DB_PASS,$url=DB_HOST) {
25 $this->Database=$database;
26 $this->Password=$password;
27 $this->User=$user;
28 $this->Url=$url;
29 $this->connect($this->Url,$this->User,$this->Password,$this->Database);
30 }
31
32 function connect($url, $user, $password, $database, $halt_on_error = true) {
33 global $error;
34 $this->_halt_on_error = $halt_on_error;
35 if ($this->_linkId == false) {
36
37 $this->_linkId=mysql_connect($url, $user, $password);
38 if ($this->_linkId == false) {
39 $error='chcipla databaza';
40 $this->exception($error);
41 return false;
42 //die();
43 }
44 $this->_url=$url;
45 $this->_user=$user;
46 $this->_password=$password;
47
48 if ($this->_linkId == false || mysql_select_db($database, $this->_linkId) == false) {
49 $this->exception("1Database failed.");
50 return false;
51 die();
52 }
53 $this->_database=$database;
54 }
55 return true;
56 }
57
58 function closeMysql() {
59 mysql_close($this->_linkId);
60 }
61
62 function query($sql) {
63
64
65
66 $this->_queryId = mysql_query($sql,$this->_linkId);
67
68 if ($_SESSION['user_id']==548) {
69 echo $sql;
70 global $timer_start;
71 echo "<BR>".SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
72 }
73
74 if ($this->_queryId == false) {
75 $this->exception("query failed ::$sql::");
76 }
77
78 return new result($this->_queryId, $sql);
79 }
80
81
82 function executequery($sql) {
83 return($this->query($sql));
84 }
85
86 function executetransaction($queries) {
87 $this->executequery("set autocommit=0");
88 if (is_array($queries)) {
89 foreach ($queries as $query) {
90 $this->executequery($query);
91 }
92 }
93 $this->executequery("commit");
94 $this->executequery("set autocommit=1");
95 }
96
97 function executeupdate($sql) {
98 return($this->update($sql));
99 }
100
101 function update($sql) {
102
103 $this->_queryId = @mysql_db_query($this->_database,$sql,$this->_linkId);
104 if ($this->_queryId == false) {
105 $this->exception("update failed.");
106 }
107 $rows=@mysql_affected_rows($this->_linkId);
108 return($rows);
109 }
110
111 function getLastInsertId() {
112 return(@mysql_insert_id($this->_linkId));
113 }
114
115 function exception($errorMessage) {
116 echo "<!-- ";
117 echo @mysql_error($this->_linkId)," (",@mysql_errno($this->_linkId),")";
118 echo "-->";
119 if ($this->_halt_on_error) {
120 die("<pre>".$errorMessage."</pre>");
121 } else {
122 echo $errorMessage."<br>";
123 return false;
124 }
125 }
126 }
127 ?>
This page took 0.302985 seconds and 4 git commands to generate.