"); } $db_recordset = mysql_query($query,$dbh) or _NODEBUG or print(" -- ERROR - cannot query '$query' in dbOpen, error: ".mysql_error()." --
"); if (!$db_recordset) { if (!function_exists('debug_backtrace')) { // php < 4.3.0 $fl = "-unknown-"; } else { $bt = debug_backtrace(); $fl = $bt[0]["file"].":".$bt[0]["line"]; } _NODEBUG or ob_flush(); error_log("PHP dbAccess error: dbOpen failed: ".preg_replace("/\s+/"," ",mysql_error()).", called from ".$fl ); } return is_resource($db_recordset); } function dbClose() { global $db_recordset; if( !is_null($db_recordset) ) { mysql_free_result($db_recordset); } $db_recordset = null; //$db_row = null; //array(); <-- ne smem zbrisat - tole bo v asp-ju treba drugače rešit! } function dbGetRow() { global $db_recordset; global $db_row; $db_row = mysql_fetch_assoc($db_recordset); return is_array($db_row); } function row($key) { global $db_row; return $db_row && array_key_exists($key, $db_row) ? $db_row[$key] : null; } function dbNumRows() { global $db_recordset; return mysql_num_rows($db_recordset); } function dbSetRow($key, $val) { global $db_row; $db_row[$key] = $val; } function dbSeek($rowNumber) { global $db_recordset; return mysql_data_seek ($db_recordset, $rowNumber); } //----------------------------------------------- function dbExec($query) { // v asp-ju se naj tu uporablja rs2 global $dbh; $retval = mysql_query($query,$dbh) or _NODEBUG or print(" -- ERROR - cannot query '$query' in dbExec, error: ".mysql_error()." --
"); if (!$retval) { if (!function_exists('debug_backtrace')) { // php < 4.3.0 $fl = "-unknown-"; } else { $bt = debug_backtrace(); $fl = $bt[0]["file"].":".$bt[0]["line"]; } _NODEBUG or ob_flush(); error_log("PHP dbAccess error: dbExec failed: ".preg_replace("/\s+/"," ",mysql_error()).", called from ".$fl ); } return $retval; // Za insert/update/delete vrne true/false - ali je uspelo ali ne. } function dbAffectedRows() { return mysql_affected_rows(); } function dbLastId() { return mysql_insert_id(); } function dbGetVal($query) { // v asp-ju se naj tu uporablja rs2 global $dbh; $db_recordset2 = mysql_query($query,$dbh) or _NODEBUG or print(" -- ERROR - cannot query '$query' in dbGetVal, error: ".mysql_error()." --
"); if (!$db_recordset2) { if (!function_exists('debug_backtrace')) { // php < 4.3.0 $fl = "-unknown-"; } else { $bt = debug_backtrace(); $fl = $bt[0]["file"].":".$bt[0]["line"]; } _NODEBUG or ob_flush(); error_log("PHP dbAccess error: dbGetVal failed: ".preg_replace("/\s+/"," ",mysql_error()).", called from ".$fl ); } $retval = @mysql_result($db_recordset2,0); mysql_free_result($db_recordset2); // ...in takoj zaprem rs2. $db_recordset2 = null; return $retval; } //----------------------------------------------- $db_recordset2 = null; $db_row2 = null; //array(); function dbOpen2($query) { global $dbh; global $db_recordset2; if (is_resource($db_recordset2)) { _NODEBUG or print(" -- ERROR - in dbOpen2, warning: this recordset is already open! --
"); } $db_recordset2 = mysql_query($query,$dbh) or _NODEBUG or print(" -- ERROR - cannot query '$query' in dbOpen2, error: ".mysql_error()." --
"); if (!$db_recordset2) { if (!function_exists('debug_backtrace')) { // php < 4.3.0 $fl = "-unknown-"; } else { $bt = debug_backtrace(); $fl = $bt[0]["file"].":".$bt[0]["line"]; } _NODEBUG or ob_flush(); error_log("PHP dbAccess error: dbOpen2 failed: ".preg_replace("/\s+/"," ",mysql_error()).", called from ".$fl ); } return is_resource($db_recordset2); } function dbClose2() { global $db_recordset2; mysql_free_result($db_recordset2); $db_recordset2 = null; //$db_row2 = null; //array(); <-- ne smem zbrisat - tole bo v asp-ju treba drugače rešit! } function dbGetRow2() { global $db_recordset2; global $db_row2; $db_row2 = mysql_fetch_assoc($db_recordset2); return is_array($db_row2); } function row2($key) { global $db_row2; return $db_row2 && array_key_exists($key, $db_row2) ? $db_row2[$key] : null; } function dbNumRows2() { global $db_recordset2; return mysql_num_rows($db_recordset2); } function dbSetRow2($key, $val) { global $db_row2; $db_row2[$key] = $val; } function dbSeek2($rowNumber) { global $db_recordset2; return mysql_data_seek ($db_recordset2, $rowNumber); } //----------------------------------------------- ?> "\\'","\\"=>"\\\\")); } } function dbSafeString ($str, $mode=0) { return "'".dbSafeStringNoq($str, $mode)."'"; } function dbSafeStringNull ($str, $mode=0) { return ($str == "")?"NULL":("'".dbSafeStringNoq($str, $mode)."'"); } function dbSafeFileUploaded ($upl,$fld,$valid,&$err,$ID_oei, $img_cross_tbl = 'oeiSlika_oei', $img_id_col = 'ID_oei') { $filename = $_FILES[$fld]["name"]; $ext = strtolower(substr($filename, strrpos($filename, "."))); $valid = $valid && ($filename != ""); //&& (($ext == ".gif") || ($ext == ".jpg")); if ($valid) { $retval = writeFileToDisk($fld,$upl,$err,$ID_oei, $img_cross_tbl, $img_id_col); $retval['name'] = "'".$retval['name']."'"; $retval['valid'] = true; return $retval; } else { return array('ID' => 'null', 'name' => 'null', 'valid' => false); } } function dbSafeBitfield ($bits) { $retval = 0; if (is_array($bits)) { foreach($bits as $val) { $retval |= dbSafeNumber0($val); } } return $retval; } function dbSafeFloat ($num) { $num = preg_replace(array('/[,.]([^,.]+)$/','/[.,]/','/#/'),array('#\1','','.'), $num); if ($num != "" and is_numeric($num)) { return floatval($num); } else { return 0; } } function dbSafeFloatNull ($num) { $num = preg_replace(array('/[,.]([^,.]+)$/','/[.,]/','/#/'),array('#\1','','.'), $num); if ($num != "" and is_numeric($num)) { return ((''.floatval($num))==$num)?floatval($num):'NULL'; } else { return 'NULL'; } } function dbSafeText ($str,$rpl=' ') { $str = preg_replace("/\\<[^>]*?\\>/",$rpl,$str); return dbSafeString($str); } function dbSafeTextNull ($str,$rpl=' ') { $str = preg_replace("/\\<[^>]*?\\>/",$rpl,$str); return dbSafeStringNull($str); } function dbSafeTextEncode ($str) { return dbSafeString(htmlentities($str)); } ?>