<?php //header("Content-Type:text/html;charset=gb2312"); include_once 'libs/database.class.php'; include_once 'libs/bb.model.php'; class Excel extends Base_Model { public function __construct() { parent::__construct(); //$this->run(); //链接数据库,普通数据库链接 /*$connect = mysql_connect('localhost','root',''); mysql_select_db('xlc_webgame',$connect);*/ } public function run() { header("Content-Type:text/html;charset=gb2312"); $handle=fopen("caixia.csv","r"); $bigArr = array(); $row=0; $sqltotal; while($res=fgetcsv($handle,1000,",")) { $use = array(); $effect = array(); $hparr = array(); $mparr = array(); $condition = array(); //$res = explode(',',$val); //$res[4] = trim(mb_convert_encoding($res[4], 'utf-8', 'gbk')); //$res[1] = trim(mb_convert_encoding($res[1], 'utf-8', 'gbk'));*/ for($i = 0; $i < 4; $i++) { if(empty($res[$i])) { $res[$i] = 0; } } if(empty($res[8])){ $res[8] = 0; } if(empty($res[12])){ $res[12] = 0; } if(empty($res[13])){ $res[13] = 0; } if($res[9]){ $use['MP'] = $res[9]; } if($res[10]){ $use['EG'] = $res[10]; } if($res[11]){ $use['HP'] = $res[11]; } if($use){ $s_use = serialize($use); }else{ $s_use = ''; } //作用 if($res[21]){ $effect['m_sb'] = $res[21]; } if($res[22]){ $effect['m_sp'] = $res[22]; } if($res[23]){ $effect['m_wf'] = $res[23]; } if($res[24]){ $effect['m_mf'] = $res[24]; } if($res[25]){ $effect['m_wg'] = $res[25]; } if($res[26]){ $hparr['s'] = $res[26]; } if($res[27]){ $hparr['b'] = $res[27]; } if($hparr){ $effect['m_hp'] = $hparr; } if($res[28]){ $mparr['s'] = $res[28]; } if($res[29]){ $mparr['b'] = $res[29]; } if($mparr){ $effect['m_mp'] = $mparr; } if($res[30]){ $effect['DEF'] = $res[30]; } if($res[31]){ $effect['ATK'] = $res[31]; } if($res[32]){ $effect['MAT'] = $res[32]; } if($res[33]){ $effect['MDF'] = $res[33]; } if($res[34]){ $effect['SPD'] = $res[34]; } if($res[35]){ $effect['success'] = $res[35]; } if($res[36]){ $effect['round'] = $res[36]; } if($effect){ $s_effect = serialize($effect); }else{ $s_effect = ''; } if($res[14]){ $condition['CON'] = $res[14]; } if($res[15]){ $condition['STR'] = $res[15]; } if($res[16]){ $condition['INT'] = $res[16]; } if($res[17]){ $condition['WIN'] = $res[17]; } if($res[18]){ $condition['DEX'] = $res[18]; } if($res[19]){ $condition['LEVEL'] = $res[19]; } if($condition){ $s_condition = serialize($condition); }else{ $s_condition = ''; } $s_detail = ''; if($res[7]){ $s_detail = $res[7]; } if($res[5]){ $s_detail .= $res[5]; } if($row > 0) { mysql_query("set names 'gbk'"); //解决汉字乱码问题 $bigArr[$row] = $res; $sql = "INSERT INTO `xlc_webgame`.`wg_skill` (`s_p_id`,`s_type`,`s_type2`,`s_d_q`,`s_name`,`name_detail`,`s_url`,`s_profession_id`,`s_use`,`s_effect`,`s_hurt_min`,`s_hurt_max`,`s_condition`,`s_detail`) VALUES ($res[0],$res[1],$res[2],$res[3],'".$res[4]."','".$res[5]."','".$res[20]."',$res[8],'".$s_use."','".$s_effect."',$res[12],$res[13],'".$s_condition."','".$s_detail."')"; $t = $this->db->query($sql); //mysql_query($sql); //$sqltotal .= $sql."<br>"; } $row++; } echo '成功插入数据库'; } }