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