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. */
8 require ("result.inc");
10 class CLASS_DATABASE {
22 var $_halt_on_error = true;
24 function CLASS_DATABASE ($database=DB_DATABASE,$user=DB_USER,$password=DB_PASS,$url=DB_HOST) {
25 $this->Database=$database;
26 $this->Password=$password;
29 $this->connect($this->Url,$this->User,$this->Password,$this->Database);
32 function connect($url, $user, $password, $database, $halt_on_error = true) {
34 $this->_halt_on_error = $halt_on_error;
35 if ($this->_linkId == false) {
37 $this->_linkId=mysql_connect($url, $user, $password);
38 if ($this->_linkId == false) {
39 $error='chcipla databaza';
40 $this->exception($error);
46 $this->_password=$password;
48 if ($this->_linkId == false || mysql_select_db($database, $this->_linkId) == false) {
49 $this->exception("1Database failed.");
53 $this->_database=$database;
58 function closeMysql() {
59 mysql_close($this->_linkId);
62 function query($sql) {
66 $this->_queryId = mysql_query($sql,$this->_linkId);
68 if ($_SESSION['user_id']==548) {
71 echo "<BR>".SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
74 if ($this->_queryId == false) {
75 $this->exception("query failed ::$sql::");
78 return new result($this->_queryId, $sql);
82 function executequery($sql) {
83 return($this->query($sql));
86 function executetransaction($queries) {
87 $this->executequery("set autocommit=0");
88 if (is_array($queries)) {
89 foreach ($queries as $query) {
90 $this->executequery($query);
93 $this->executequery("commit");
94 $this->executequery("set autocommit=1");
97 function executeupdate($sql) {
98 return($this->update($sql));
101 function update($sql) {
103 $this->_queryId = @mysql_db_query($this->_database,$sql,$this->_linkId);
104 if ($this->_queryId == false) {
105 $this->exception("update failed.");
107 $rows=@mysql_affected_rows($this->_linkId);
111 function getLastInsertId() {
112 return(@mysql_insert_id($this->_linkId));
115 function exception($errorMessage) {
117 echo @mysql_error($this->_linkId)," (",@mysql_errno($this->_linkId),")";
119 if ($this->_halt_on_error) {
120 die("<pre>".$errorMessage."</pre>");
122 echo $errorMessage."<br>";