2022-07-07  点击量: 20

php版json数据导入代码

阿里云

仅供参考

function wdja_cms_admin_manage_jsondisp()
{
  date_default_timezone_set("Asia/Shanghai");
  $starttime = microtime(1);
  global $conn, $slng;
  global $ngenre, $nclstype, $npagesize, $nlisttopx;
  global $ndatabase, $nidfield, $nfpre;
  $tbackurl = $_GET['backurl'];
  $tjson = '..'.ii_cstr($_POST['json']);
  if(file_exists($tjson)){
        $json_file = fopen($tjson,'r');
        $tfile = json_decode(fgets($json_file), true);
        $num = count($tfile);
        $long = ceil($num/50);
        for($i=0;$i<$long;$i++){
            $tsqlstr = '';
            $sql_sub = '';
            for($j=0;$j<50;$j++){
            $num_sub = $i*50 + $j;
            $ttopic = ii_cstr($tfile[$num_sub]['word']);
            $tsource = ii_cstr($tfile[$num_sub]['derivation']);
            $texample = ii_cstr($tfile[$num_sub]['example']);
            $tpinyin = ii_cstr($tfile[$num_sub]['pinyin']);
            $tshouzimu = ii_cstr($tfile[$num_sub]['abbreviation']);
            $tcontent = ii_cstr($tfile[$num_sub]['explanation']);
                //拼接mysql语句
                if($j==50 - 1) $sql_plus = ';';
                else $sql_plus = ',';
                // && !mm_search_field($ngenre,$ttopic,'topic') 判断是否标题重复,会耗费大量资源,不建议使用.
                if(!ii_isnull($ttopic)) $sql_sub .= "('" . $ttopic . "','".$tsource."','".$texample."','".$tpinyin."','".$tshouzimu."','".$tcontent."','" . ii_now() . "','" . ii_now() . "','0','0','$slng')".$sql_plus;
            }
            //拼接后的mysql语句进行入库
            $tsqlstr = "insert into $ndatabase (" . ii_cfname('topic') . "," . ii_cfname('source') . "," . ii_cfname('example') . "," . ii_cfname('pinyin') . "," . ii_cfname('shouzimu') . "," . ii_cfname('content') . "," . ii_cfname('time') . "," . ii_cfname('update') . ", " . ii_cfname('hidden') . "," . ii_cfname('good') . "," . ii_cfname('lng') . ") values ".$sql_sub;
            ii_conn_query($tsqlstr, $conn);
        }
      $endtime = microtime(1);
      $protime = number_format((($endtime - $starttime) * 1000), 3, '.', '');
      wdja_cms_admin_msg(ii_itake('global.lng_public.add_succeed', 'lng').$num.'条数据,耗时'.$protime.'ms', $tbackurl, 1);
    }
}

 

 

评论已关闭!