eq($where_valeur) ." LIMIT 1"; $rst = $this->sql->query($query); if($v_rst = $this->sql->fetch_assoc($rst)) $value = $v_rst["res"]; } catch(Exception $_e) { $value = false; } return $value; } function set($table, $champ, $valeur, $where_champ, $where_valeur) { try { $query = "UPDATE #--".$table ." SET `".$champ."`=".$this->eq($valeur) ." WHERE `".$where_champ."`=".$this->eq($where_valeur) ." LIMIT 1"; $this->sql->query($query); } catch(Exception $_e) { return false; } return true; } # ---------------------------------------------------------------------------------------- # # ci-dessous # # - utils : des fonctions courantes dans le traitement des données # (dates, echapement des simples quotes...) # # - fonctions de base : des squelettes de fonctions pour l'accès en base # (liste, ajout, modification...) # # ---------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------- # utils # function html($content) { return str_replace ( array(">", "<", """), array(">", "<", "\""), $content ); } function encode_email($email) { return "ascii_entities("mailto:".$email)."\">" .$this->ascii_entities($email) .""; } function ascii_entities($content) { $entities = ""; $n = 0; while($n < strlen($content)) { $entities .= "&#".ord($content[$n]).";"; $n++; } return $entities; } function resume($content, $max) { $resume = ""; $v_content = explode(" ", $content); for($n = 0; $n < $max; $n++) $resume .= $v_content[$n]." "; return $resume; } function eq($content) { return (isset($content) ? "'".str_replace("'", "\'", $content)."'" : "NULL"); } function frenchdate($i) { if(ereg("([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})", $i, $regs)) $i = $regs[3]."-".$regs[2]."-".$regs[1]; return $i; } function englishdate($i) { if(ereg("([0-9]{1,2})-([0-9]{1,2})-([0-9]{2,4})", $i, $regs)) $i = $regs[3]."-".$regs[2]."-".$regs[1]; return $i; } function unix_time($mysql_timestamp) { if ( preg_match('/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $mysql_timestamp, $pieces) || preg_match('/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $mysql_timestamp, $pieces) ) { $unix_time = mktime($pieces[4], $pieces[5], $pieces[6], $pieces[2], $pieces[3], $pieces[1]); } elseif ( preg_match('/\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/', $mysql_timestamp) || preg_match('/\d{2}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/', $mysql_timestamp) || preg_match('/\d{4}\-\d{2}\-\d{2}/', $mysql_timestamp) || preg_match('/\d{2}\-\d{2}\-\d{2}/', $mysql_timestamp) ) { $unix_time = strtotime($mysql_timestamp); } elseif ( preg_match('/(\d{4})(\d{2})(\d{2})/', $mysql_timestamp, $pieces) || preg_match('/(\d{2})(\d{2})(\d{2})/', $mysql_timestamp, $pieces) ) { $unix_time = mktime(0, 0, 0, $pieces[2], $pieces[3], $pieces[1]); } return $unix_time; } function str_to_hex($str) { $hex = ""; $n = 0; while($n < strlen($str)) { $hex_char = dechex(ord($str[$n])); if(strlen($hex_char) == 1) $hex_char = "0".$hex_char; $hex .= $hex_char; $n++; } return $hex; } function is_email($email) { $atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]'; $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; return preg_match ( '/^'.$atom.'+'.'(\.'.$atom.'+)*'.'@'.'('.$domain.'{1,63}\.)+'.$domain.'{2,63}$/i', $email ); } # ---------------------------------------------------------------------------------------- # fonctions de base # function list_() { $list = array(); try { $query = "SELECT * FROM #--table"; $rst = $this->sql->query($query); while($v_rst = $this->sql->fetch_assoc($rst)) $list[$v_rst["id"]] = $v_rst; $this->sql->free_result($rst); } catch(Exception $_e) { $list = false; } return $list; } function add_($value) { try { $query = "INSERT INTO #--table(value) VALUES" ."( ".$this->eq($value) .")"; $this->sql->query($query); } catch(Exception $_e) { return false; } return true; } function set_($id, $value) { try { $query = "UPDATE #--table SET" ." value=".$this->eq($value) ." WHERE id=".$this->eq($id); $this->sql->query($query); } catch(Exception $_e) { return false; } return true; } function del_($id) { try { $query = "DELETE FROM #--table WHERE id=".$this->eq($id); $this->sql->query($query); } catch(Exception $_e) { return false; } return true; } } ?>