| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | // Modul pro práci s databází //
|
|---|
| 4 |
|
|---|
| 5 | require_once('config.php');
|
|---|
| 6 | //require_once('error.php');
|
|---|
| 7 |
|
|---|
| 8 | // Předpona před názvem tabulek
|
|---|
| 9 | if(!isset($DB_Prefix)) $DB_Prefix = '';
|
|---|
| 10 |
|
|---|
| 11 | //echo('Tuto stránku nelze zobrazit přímo!');
|
|---|
| 12 | $DB_LastResults = array(); // Dočasné uchování výsledků
|
|---|
| 13 |
|
|---|
| 14 | // Inicializace databáze //
|
|---|
| 15 | function DB_Init($host,$user,$password,$name)
|
|---|
| 16 | {
|
|---|
| 17 | global $DB_Tables;
|
|---|
| 18 | $link = mysql_connect($host,$user,$password);
|
|---|
| 19 | //echo(mysql_errno());
|
|---|
| 20 | if(mysql_errno()!=FALSE) die(mysql_error()); //trigger_error('DB: '.mysql_error(), E_USER_ERROR);
|
|---|
| 21 | mysql_select_db($name);
|
|---|
| 22 | if(mysql_errno()==1049) db_query("CREATE DATABASE $name");
|
|---|
| 23 | $Tables = mysql_list_tables($name);
|
|---|
| 24 | $DB_Tables = array();
|
|---|
| 25 | for($I=0;$I<mysql_num_rows($Tables);$I++)
|
|---|
| 26 | {
|
|---|
| 27 | $DB_Tables[$I] = mysql_tablename($Tables,$I);
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 | DB_Init($Options['DB_Host'],$Options['DB_User'],$Options['DB_Password'], $Options['DB_Database']);
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | // Dotaz na databázi //
|
|---|
| 34 | function DB_Query($query)
|
|---|
| 35 | {
|
|---|
| 36 | global $db_result,$DB_LastResults;
|
|---|
| 37 | //echo('DB: Poľadavek('.$query.')<br>');
|
|---|
| 38 | //$DB_LastResults[0] = mysql_query($query);
|
|---|
| 39 | //System_ShowArray($DB_LastResults);
|
|---|
| 40 | $db_result = mysql_query($query);
|
|---|
| 41 | if(mysql_error())
|
|---|
| 42 | {
|
|---|
| 43 | //echo(debug_backtrace());
|
|---|
| 44 | //var_dump(debug_backtrace());
|
|---|
| 45 |
|
|---|
| 46 | trigger_error('DB: '.mysql_error(), E_USER_ERROR);
|
|---|
| 47 | //obsluha_chyb(mysql_errno(),mysql_error(),'','','');
|
|---|
| 48 |
|
|---|
| 49 | //echo('DB: Chyba poľadavku číslo '.mysql_errno().'!('.mysql_error().')<br>Poľadavek: '.$query.'<br>');
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | // Výběr daląího řádku //
|
|---|
| 54 | function DB_Row()
|
|---|
| 55 | {
|
|---|
| 56 | global $db_result;
|
|---|
| 57 | return(mysql_fetch_array($db_result));
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | // Počet vrácených řádků //
|
|---|
| 61 | function DB_NumRows()
|
|---|
| 62 | {
|
|---|
| 63 | global $db_result;
|
|---|
| 64 | return(mysql_num_rows($db_result));
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | // Uschová výsledek
|
|---|
| 68 | function DB_Save()
|
|---|
| 69 | {
|
|---|
| 70 | global $db_result,$DB_LastResults;
|
|---|
| 71 | array_push($DB_LastResults,$db_result);
|
|---|
| 72 | //System_ShowArray($DB_LastResults);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | // Načte předchozí výsledek
|
|---|
| 76 | function DB_Load()
|
|---|
| 77 | {
|
|---|
| 78 | global $db_result,$DB_LastResults;
|
|---|
| 79 | $db_result = array_pop($DB_LastResults);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | // SELECT
|
|---|
| 83 | function DB_Select($Table,$What,$Condition = 1)
|
|---|
| 84 | {
|
|---|
| 85 | global $DB_Prefix;
|
|---|
| 86 | DB_Query("SELECT ".$What." FROM ".$DB_Prefix.$Table." WHERE ".$Condition);
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | // DELETE
|
|---|
| 90 | function DB_Delete($Table,$Condition)
|
|---|
| 91 | {
|
|---|
| 92 | global $DB_Prefix;
|
|---|
| 93 | DB_Query("DELETE FROM ".$DB_Prefix.$Table." WHERE ".$Condition);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | // Vloľení nového řádku do databáze //
|
|---|
| 97 | function DB_Insert($table,$data)
|
|---|
| 98 | {
|
|---|
| 99 | global $DB_Prefix;
|
|---|
| 100 | $name = '';
|
|---|
| 101 | $values = '';
|
|---|
| 102 | foreach($data as $key => $value)
|
|---|
| 103 | {
|
|---|
| 104 | //$value = strtr($value,'"','\"');
|
|---|
| 105 | $name .= ",".$key;
|
|---|
| 106 | if($value=='NOW()') $values .= ",".$value;
|
|---|
| 107 | else $values .= ',"'.$value.'"';
|
|---|
| 108 | }
|
|---|
| 109 | $name = substr($name,1);
|
|---|
| 110 | $values = substr($values,1);
|
|---|
| 111 | db_query("INSERT INTO ".$DB_Prefix."$table ($name) VALUES($values)");
|
|---|
| 112 | //echo("INSERT INTO $table ($name) VALUES($values)");
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | // Vloľení nového řádku do databáze //
|
|---|
| 116 | function DB_Update($table,$condition,$data)
|
|---|
| 117 | {
|
|---|
| 118 | global $DB_Prefix;
|
|---|
| 119 | $name = '';
|
|---|
| 120 | $values = '';
|
|---|
| 121 | foreach($data as $key => $value)
|
|---|
| 122 | {
|
|---|
| 123 | //$value = strtr($value,'"','\"');
|
|---|
| 124 | if($value!='NOW()') $value = '"'.$value.'"';
|
|---|
| 125 | $values .= ", ".$key."=".$value;
|
|---|
| 126 | }
|
|---|
| 127 | $values = substr($values,2);
|
|---|
| 128 | DB_Query("UPDATE ".$DB_Prefix.$table." SET $values WHERE ($condition)");
|
|---|
| 129 | //echo("UPDATE $table WHERE($condition) SET ($values)");
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | ?>
|
|---|