site = $s; $this->user = $u; $this->pass = $p; $this->database = $d; $this->spojeni = @mysql_connect($s, $u, $p) or die("Omlouváme se, nelze se spojit s databázovým serverem."); @mysql_select_db($d) or die("Omlouváme se, databáze neexistuje."); //@mysql_query('SET NAMES CP1250'); @mysql_query('SET NAMES UTF8'); //if($err_stream){ // $this->error_stream = $cesta_k_data; //} else { $this->error_stream = $cesta_k_data; //} } function close(){ @mysql_close($this->spojeni); } function error($errno, $errmess) { // $errno - cislo chyby, $errmess - popis chyby echo StrFTime ("%d.%m.%Y %H:%M:%S")." > $errno > ".$errmess."\n"; echo $this->error_stream; $fp = fopen($this->error_stream, "a"); fputs ($fp, StrFTime ("%d.%m.%Y %H:%M:%S")." > $errno > ".strip_tags($errmess)."\r\n\r\n"); fclose ($fp); } function query($s, $nezapisovat = 0){ global $DEBUG_SQL_QUERY, $DEBUG_SQL_QUERY_FILE_HANDLE ,$cesta_k_req; if($DEBUG_SQL_QUERY == "DEBUG"){ fwrite($DEBUG_SQL_QUERY_FILE_HANDLE, $s."\r\n"); } if($nezapisovat == 0){ //saveApplicationLog($s); } $result = @mysql_query($s); if(!$result){ $this->error(2, "Query error in [$s]. ".mysql_error()."."); } $this->last_query = $result; return $this->last_query; } function fetch_array($q, $limit = 0){ global $result; if($limit > 0){ $q .= " LIMIT ".$limit; } if ($q) { $this->query($q); } $num = $this->num_rows($result); for ($i = 0; $i < $num; $i++) { $arr[] = @mysql_fetch_array($this->last_query); } if(isset($arr) && is_array($arr)){ if($limit == 1 && is_array($arr[0])){ foreach($arr[0] AS $key=>$val){ $array[$key] = stripslashes($val); } $arr = $array; } return $arr; } else { return false; } } function num_rows($result = "") { if ($result == "") { return @mysql_num_rows($this->last_query); } else { return @mysql_num_rows($result); } } function affected_rows(){ return @mysql_affected_rows($this->spojeni); } function insert_id(){ return @mysql_insert_id(); } function fetch_all(){ $rows = $this->num_rows(); $a = array(); for ($i=0; $i<$rows; $i++) { $a[$i] = $this->fetch_array(); } return $a; } function exists_table($name) { $this->last_query = @mysql_query("DESCRIBE $name"); if ($this->last_query): return $this->fetch_all(); else: return false; endif; } function index_value($q, $index, $value = "") { $result = $this->query($q); if ($result) { while($row = mysql_fetch_array($result)){ $arr[$row[$index]] = stripslashes($row[$value]); } if(isset($arr)){ return $arr; } } else { return false; } } } // endclass ?> spojeni = $s; $this->idLang = $j; //$this->preklady = array(); //$this->soubor_neni_v_db = $cesta_k_data.'data/preklady_neni_v_db.txt'; //$this->soubor_je_prazdny = $cesta_k_data.'data/preklady_je_prazdny.txt'; } function translate($code) { $idLang = intval($this->idLang); //$code = $this->code; $tr = $this->spojeni->fetch_array("SELECT `translate` FROM `translates` WHERE `code` REGEXP '^".$code."$' AND `idLanguage` = ".$idLang, 1 ); if(isset($tr) && is_array($tr) && strlen($tr['translate']) ){ return $tr['translate']; } else{ $this->spojeni->query("REPLACE INTO `translates` (`code`, `idLanguage`) VALUES ('".$code."', ".$idLang.")" ); return $code; } } } ?>