hostname=$hostname; $this->username=$username; $this->password=$password; $this->database=$database; $this->link = mysql_connect($this->hostname,$this->username,$this->password) or die("Sorry,can not connect to database"); mysql_query("SET NAMES UTF8"); mysql_select_db($this->database,$this->link); } function query($sql){ //这个函数用于送出查询语句并返回结果,常用。 if($this->result=mysql_query($sql,$this->link)) return $this->result; else { //这里是显示SQL语句的错误信息,主要是设计阶段用于提示。正式运行阶段可将下面这句注释掉。 echo "SQL语句错误: $sql

错误信息: ".mysql_error(); return false; } } /* 以下函数用于从结果取回数组,一般与 while()循环、$db->query($sql) 配合使用,例如: $result = $db->query("select * from mytable"); while($row=$db->getarray($result)){ echo "$row[id] "; } */ function getarray($result){ return @mysql_fetch_array($result); } /* 得表字段 */ //$fields = mysql_list_fields("database1", "table1"); //$columns = mysql_num_fields($fields); function getfield($result){ $fields=mysql_list_fields('50',$result,$this->link); $columns=mysql_num_fields($fields); for ($i = 0; $i < $columns; $i++) { $tf[]=mysql_field_name($fields, $i); } return $tf; } /* 得表字段数量 */ /* 具体字段名称 function mysql_field_name($result){ return @mysql_field_name($result); } /* 以下函数用于取得SQL查询的第一行,一般用于查询符合条件的行是否存在,例如: 用户从表单提交的用户名$username、密码$password是否在用户表“user”中,并返回其相应的数组: if($user=$db->getfirst("select * from user where username='$username' and password='$password' ")) echo "欢迎 $username ,您的ID是 $user[id] 。"; else echo "用户名或密码错误!"; */ function getfirst($sql){ return @mysql_fetch_array($this->query($sql)); } /* 以下函数返回符合查询条件的总行数,例如用于分页的计算等要用到,例如: $totlerows=$db->getcount("select * from mytable"); echo "共有 $totlerows 条信息。"; */ function getcount($sql){ return @mysql_num_rows($this->query($sql)); } /*   以下函数用于更新数据库,例如添加一个用户、更改用户密码和删除一个用户:   $db->Execute("insert into user (userid,username,password) values (null,'$username','$password')");   $db->Execute("update user set password='$new_password' where userid='$userid' ");   $db->Execute("delete from user where userid='$userid'"); */ function Execute($sql){ return $this->query($sql); } /* 以下函数用于取得刚插入行的id */ function getid(){ return mysql_insert_id(); } /* 以下函数用于断开数据库的连接 */ function close(){ mysql_close($this->link); } /* 以下函数用于使用转义字符,保证系统安全 */ function escapeString($str){ return mysql_escape_string($str); } } $db = new dbClass($hostname,$username,$password,$database); function inserttable($tablename, $insertsqlarr, $returnid=0) { global $db; $insertkeysql = $insertvaluesql = $comma = ''; foreach ($insertsqlarr as $insert_key => $insert_value) { $insertkeysql .= $comma.$insert_key; $insertvaluesql .= $comma.'\''.$insert_value.'\''; $comma = ', '; } $db->query('INSERT INTO '.$tablename.' ('.$insertkeysql.') VALUES ('.$insertvaluesql.') '); if($returnid) { $id = $db->getid(); return $id; } } function thtab($tablename, $insertsqlarr) { global $db; $insertkeysql = $insertvaluesql = $comma = ''; foreach ($insertsqlarr as $insert_key => $insert_value) { $insertkeysql .= $comma.$insert_key; $insertvaluesql .= $comma."'".unescape($insert_value)."'"; $updatavalue .= $comma.$insert_key.'="'.unescape($insert_value).'"'; $comma = ', '; } //$sql= 'INSERT INTO '.$tablename.' VALUES ('.$insertvaluesql.') ON DUPLICATE KEY UPDATE '.$updatavalue.''; //return $sql; $db->query('INSERT INTO '.$tablename.' VALUES ('.$insertvaluesql.') ON DUPLICATE KEY UPDATE '.$updatavalue.''); } function unescape($str) { if(substr($str,0,2) == "&#"){ $str = rawurldecode($str); preg_match_all("/&#\d+/",$str,$r); $ar = $r[0]; foreach($ar as $k=>$v) { if(substr($v,0,2) == "&#") { $ar[$k] =unicode_utf8(substr($v,2)); // $ar[$k] = iconv("UCS-2","UTF-8",pack("n",substr($v,2))); } } return join("",$ar); }else{ return $str; } } function unicode_utf8($c) { if(! is_numeric($c)) { $c = hexdec(bin2hex($c)); } $str= ""; if ($c < 0x80) { $str .= $c; } else if ($c < 0x800) { $str .= chr(0xC0 | $c>>6); $str .= chr(0x80 | $c & 0x3F); } else if ($c<0x10000) { $str .= chr(0xE0 | $c>>12); $str .= chr(0x80 | $c>>6 & 0x3F); $str .= chr(0x80 | $c & 0x3F); } else if ($c < 0x200000) { $str .= chr(0xF0 | $c>>18); $str .= chr(0x80 | $c>>12 & 0x3F); $str .= chr(0x80 | $c>>6 & 0x3F); $str .= chr(0x80 | $c & 0x3F); } return $str; } function deletetable($tablename, $wheresqlarr) { global $db; if(empty($wheresqlarr)) { $db->query('TRUNCATE TABLE '.$tablename); } else { $db->query('DELETE FROM '.$tablename.' WHERE '.getwheresql($wheresqlarr)); } } function updatetable($tablename, $setsqlarr, $wheresqlarr) { global $db; $setsql = $comma = ''; foreach ($setsqlarr as $set_key => $set_value) { $setsql .= $comma.$set_key.'=\''.$set_value.'\''; $comma = ', '; } $db->query('UPDATE '.$tablename.' SET '.$setsql.' WHERE '.getwheresql($wheresqlarr)); } function selecttable($tablename, $selectsqlarr, $wheresqlarr, $plussql='') { global $db; $selectsql = $comma = ''; if(count($selectsqlarr)) { foreach ($selectsqlarr as $select_key => $select_value) { $selectsql .= $comma.$select_value; $comma = ', '; } } else { $selectsql = '*'; } $results = array(); $strSql = 'SELECT '.$selectsql.' FROM '.$tablename.' WHERE '.getwheresql($wheresqlarr).' '.$plussql; if($_GET['debug']=='zgs'){ echo ""; } $query = $db->query($strSql); // echo getwheresql($wheresqlarr); while ($r_array = $db->getarray($query)) { $results[] = $r_array; } return $results; } function getwheresql($wheresqlarr) { $result = $comma = ''; if(empty($wheresqlarr)) { $result = '1'; } elseif(is_array($wheresqlarr)) { foreach ($wheresqlarr as $key => $value) { $result .= $comma.$key.'=\''.$value.'\''; $comma = ' AND '; } } else { $result = $wheresqlarr; } return $result; } $dbass='/data2/www/db.duowan.com/'; ?>(尖括号) [12] ()(括号) [13] +(加号) [14] CR(回车符,ASCII 0x0d) [15] LF(换行,ASCII 0x0a) [16] ,(逗号) [17] \(反斜杠) "@",??可能有邮箱 */ function postget($var,$var_type='',$max_len=32) { $vowels = array( "|","%", "&", ";","'", "\"", "\\", "<", ">","(",")","+",",",",","include","script","exec","eval"); if (isset ( $_POST [$var] )) { $input = $_POST [$var]; }elseif(isset($_GET[$var])){ $input = $_GET [$var]; }else{ $input = ''; } if($var_type=='int'){ $input = intval($input); } $input = str_replace($vowels, "", trim ($input)); //if($var_type=='string'){ // $input = htmlentities($input, ENT_QUOTES, 'UTF-8'); //} $input = mysql_escape_string ($input); if (strlen ( $input ) > $max_len) { $input = ''; } return $input; } function getid($dn, $pid) { global $db; $row = $db->getfirst ( 'select id from `' . $dn . '` where pid="' . $pid . '"' ); $id = $row ['id']; return $id; } function putid($id) { $pid = substr ( md5 ( $id . 'd1w2' ), 4, 10 ); return $pid; } $quality_color = array ( 'common' => 'white', 'rare' => 'green', 'legend' => 'blue', 'unique' => 'org', 'junk' => 'gray', 'epic' => 'epic' ) ; $item_ly = array (1 => '掉落', 3 => 'NPC', 5 => '任务', 9 => '采集制作' ); $type_id = array ( 1 => '怪物', 2 => '商人', 3 => 'NPC', 4 => 'Boss' ) ; $c_ = array (1 => '武器', 2 => '防具', 'a' => '饰品', 3 => '强化', 4 => '材料', 5 => '消耗品', 6 => '技能书', 7 => '图案', 8 => '任务物品', 9 => '杂物', 'b' => '要塞攻城' ); $c_1 = array (1 => '单手剑', 2 => '双手剑', 3 => '短剑', 4 => '法杖', 5 => '法书', 6 => '宝珠', 7 => '弓', 8 => '长柄武器', 9 => '权杖', 0 => '其他' ); $c_2 = array (1 => '布甲', 2 => '皮甲', 3 => '锁甲', 4 => '金属', 6 => '盾牌' ); $c_3 = array (1 => '强化石', 2 => '神石', 3 => '魔石', 4 => '封魂石', 5 => '烙印石' ); $c_4 = array (2 => '提炼石', 3 => '掉落材料', 4 => '售卖材料', 5 => '二级材料(普通)', 6 => '二级材料(装备)' ); $c_5 = array (1 => '食品', 2 => '药水', 3 => '法术卷轴', 4 => '特效道具', 5 => '变身道具', 6 => '染色剂', 7 => '绷带', 8 => '缚灵石', 9 => '奇斯克', 0 => '施法材料' ); $c_6 = array (1 => '技能书', 2 => '表情卡片' ); $c_7 = array (1 => '武器锻造', 2 => '盔甲锻造', 3 => '炼金术', 4 => '手工', 5 => '料理', 6 => '裁缝', 7 => '变换' ); $c_8 = array (1 => '任务道具', 2 => '钥匙', 3 => '其他' ); $c_9 = array (1 => '车床', 3 => '掉落杂物', 4 => '铸钱', 5 => '勋章', 7 => '未分类' ); $c_b = array (1 => '攻城配件', 2 => '攻城武器' ); $c_2_1 = array (2 => '胸部', 3 => '肩膀', 4 => '手套', 5 => '腿', 6 => '脚' ); $c_a = array (1 => '戒指', 2 => '耳环', 3 => '项链', 4 => '翅膀', 5 => '腰带', 7 => '头饰' ); $zbbw = array ('waist' => '腰带', 'shoulder' => '披风', 'right_or_left_finger' => '戒指', 'right_or_left_ear' => '耳环', 'right_or_left_battery' => '封魂石', 'neck' => '项链', 'leg', 'head' => '帽子', 'foot' => '鞋', 'glove' => '手套', 'main_or_sub' => '主手或副手', 'sub' => '副手', 'torso' => '上衣', 'main' => '主手' ); $quest_arr = array ( 'task' => '委托', 'quest' => '一般', 'mission' => '使命' ) ; $skilltype_arr = array ( 'Passive' => '被动', 'Active' => '主动', 'Toggle' => '触发', 'Maintain' => '持续', 'Provoked' => '激发', '' => '无' ) ; $skillzy_arr = array ( '1' => '战士', '2' => '侦查者', '3' => '法师', '4' => '祭师', '5' => '剑星', '6' => '守护星', '7' => '杀星', '8' => '弓星', '9' => '魔道星', '10' => '精灵星', '11' => '护法星', '12' => '治愈星', '13' => '全部' ) ; $zz_arr = array (1 => '天族', 2 => '魔族', 3 => '全部' ); function itemColor($field = "") { global $quality_color; if ($quality_color [$field]) return $quality_color [$field]; else return $field; } function npctype($field) { global $type_id; return $type_id [$field]; if ($type_id [$field]) return $type_id [$field]; else return $field; } function questtype($field) { global $quest_arr; return $quest_arr [$field]; if ($quest_arr [$field]) return $quest_arr [$field]; else return $field; } function itemtype($field) { global $c_; return $c_ [$field]; if ($c_ [$field]) return $c_ [$field]; else return $field; } function zz($field) { global $zz_arr; return $zz_arr [$field]; if ($zz_arr [$field]) return $zz_arr [$field]; else return $field; } function skilltype($field) { global $skilltype_arr; return $skilltype_arr [$field]; if ($skilltype_arr [$field]) return $skilltype_arr [$field]; else return $field; } function skillzy($field) { global $skillzy_arr; return $skillzy_arr [$field]; if ($skillzy_arr [$field]) return $skillzy_arr [$field]; else return $field; } function stripsearchkey($string) { if (is_array ( $string )) { foreach ( $string as $key => $val ) { $string [$key] = stripsearchkey ( $val ); } } else { $string = trim ( $string ); $string = str_replace ( '*', '%', addcslashes ( $string, '%_' ) ); $string = str_replace ( '_', '\_', $string ); $string = str_replace ( '<', '', $string ); } return $string; } function selecttable2($tablename, $selectsqlarr, $wheresqlarr, $plussql = '') { global $db; $selectsql = $comma = ''; if (count ( $selectsqlarr )) { foreach ( $selectsqlarr as $select_key => $select_value ) { $selectsql .= $comma . $select_value; $comma = ', '; } } else { $selectsql = '*'; } $results = array (); $query = $db->query ( 'SELECT ' . $selectsql . ' FROM ' . $tablename . ' WHERE ' . getwheresql2 ( $wheresqlarr ) . ' ' . $plussql ); while ( $r_array = $db->getarray ( $query ) ) { $results [] = $r_array; } return $results; } //function getwheresql($wheresqlarr) { // $result = $comma = ''; // if(empty($wheresqlarr)) { // $result = '1'; // } elseif(is_array($wheresqlarr)) { // foreach ($wheresqlarr as $key => $value) { // $result .= $comma.$key.'=\''.$value.'\''; // $comma = ' AND '; // } // } else { // $result = $wheresqlarr; // } // return $result; //} function getwheresql2($wheresqlarr) { $result = $comma = ''; if (empty ( $wheresqlarr )) { $result = '1'; } elseif (is_array ( $wheresqlarr )) { foreach ( $wheresqlarr as $value ) { $result .= $comma . $value; $comma = ' AND '; } } else { $result = $wheresqlarr; } return $result; } //function getvalue($sql,$value){ //global $db,$value1; //$value1=''; //$res=$db->query($sql); //if($row=$db->getarray($res)){ //$value1=$row[$value]; //} //return $value1; //} //分页函数 function multi($num, $perpage, $curr_page, $mpurl) { $multipage = ''; if ($num > $perpage) { $page = 10; $offset = 2; $pages = ceil ( $num / $perpage ); if ($pages > 15) $pages = 15; $from = $curr_page - $offset; $to = $curr_page + $page - $offset - 1; if ($page > $pages) { $from = 1; $to = $pages; } else { if ($from < 1) { $to = $curr_page + 1 - $from; $from = 1; if (($to - $from) < $page && ($to - $from) < $pages) { $to = $page; } } elseif ($to > $pages) { $from = $curr_page - $pages + $to; $to = $pages; if (($to - $from) < $page && ($to - $from) < $pages) { $from = $pages - $page + 1; } } } if (! $mpurl) $mpurl = "http://" . $_SERVER ["HTTP_HOST"] . $_SERVER ["REQUEST_URI"]; $mpurl = mysql_real_escape_string ( strip_tags ( rawurldecode ( $mpurl ) ) ); $mpurl = str_replace ( array ('\'', '"', '>', '<', '\\', ';' ), '', $mpurl ); $parse_url = parse_url ( $mpurl ); $url_query = $parse_url ["query"]; if ($url_query) $mpurl = ereg_replace ( '[&?]page=[0-9]+', '', $mpurl ); $mpurl .= strpos ( $mpurl, '?' ) ? '&' : '?'; $multipage .= "
  • "; if ($to > 15) $to = 15; for($i = $from; $i <= $to; $i ++) { if ($i != $curr_page) { $multipage .= "
  • $i
  • "; } else { $multipage .= '
  • ' . $i . '
  • '; } } $multipage .= $pages > $page ? "
  • " : "
  • "; } return $multipage; } // //
    //
    一共有413条记录
    //
    // //
    //
    $idStrArr = array (); $idStrArr [0] = "7"; $idStrArr [1] = "X"; $idStrArr [2] = "2"; $idStrArr [3] = "1"; $idStrArr [4] = "4"; $idStrArr [5] = "Z"; $idStrArr [6] = "a"; $idStrArr [7] = "o"; $idStrArr [8] = "c"; $idStrArr [9] = "3"; function encodeID($inID) { global $idStrArr; $inID = ( string ) $inID; $outID = ""; for($i = 0; $i < strlen ( $inID ); $i ++) $outID .= $idStrArr [$inID [$i]]; return $outID; } function decodeID($str) { global $idStrArr; $strIDArr = array_flip ( $idStrArr ); $str = ( string ) $str; $outStr = ""; for($i = 0; $i < strlen ( $str ); $i ++) $outStr .= $strIDArr [$str [$i]]; return $outStr; } ?>