X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=inc%2Fdatabase.inc;fp=inc%2Fdatabase.inc;h=5d2e5454a4b400d12b2ca9dbdacd66dac14b8017;hb=bc13d5d6e1834068f8b690c32bba114e352dacdd;hp=0000000000000000000000000000000000000000;hpb=07269e54b4e79c0a5e77d8f378cf0849bd8276e5;p=mirrors%2FKyberia-bloodline.git diff --git a/inc/database.inc b/inc/database.inc new file mode 100644 index 0000000..5d2e545 --- /dev/null +++ b/inc/database.inc @@ -0,0 +1,95 @@ +connect("$this->Url","$this->User","$this->Password","$this->Database"); +} + +function connect($url, $user, $password, $database, $halt_on_error = true) { + $this->_halt_on_error = $halt_on_error; + if ($this->_linkId == false) { + $this->_linkId=mysql_connect($url, $user, $password); + if ($this->_linkId == false) { + $this->exception("weej databazka to nerozdychava ;)"); + return false; + die(); + } + $this->_url=$url; + $this->_user=$user; + $this->_password=$password; + if ($this->_linkId == false || mysql_select_db($database, $this->_linkId) == false) { + $this->exception("1Database failed."); + return false; + die(); + } + $this->_database=$database; + } + return true; +} + +function closeMysql() { + mysql_close($this->_linkId); +} + +function query($sql) { + global $user_id; + if ($user_id==220 && $_GET['debug']) echo $sql; + $this->_queryId = mysql_db_query($this->_database,$sql,$this->_linkId); + if ($this->_queryId == false) { + $this->exception("query failed ::$sql::"); + } + + return new result($this->_queryId, $sql); + } + + +function executequery($sql) { + return($this->query($sql)); +} + +function executeupdate($sql) { + return($this->update($sql)); +} + +function update($sql) { + + $this->_queryId = @mysql_db_query($this->_database,$sql,$this->_linkId); + if ($this->_queryId == false) { + $this->exception("update failed."); + } + $rows=@mysql_affected_rows($this->_linkId); + return($rows); +} + +function getLastInsertId() { + return(@mysql_insert_id($this->_linkId)); +} + +function exception($errorMessage) { + echo ""; + if ($this->_halt_on_error) { + die("
".$errorMessage."
"); + } else { + echo $errorMessage."
"; + return false; + } + } +} +?> \ No newline at end of file