Home > php教程 > php手册 > php实现refresh刷新页面进入批量导入数据

php实现refresh刷新页面进入批量导入数据

WBOY
Release: 2016-06-02 09:13:55
Original
846 people have browsed it

我的这个功能的原因是参考dedecms生成html页面的原理,只是dedecms使用的是js跳转而我使用的是refresh进行跳转,效果是一样的,下面我们一起来看一个php实现批量导入数据的方法.

因为我有1000W数据一次导入数据库肯定是不可行了,所以我就导致了每一次导入50条或更多数据,然后下次再刷新一次这样就可以解决这个问题了,代码如下:

<?php
set_time_limit(0);
//连接数据库
$s = isset($_GET[&#39;s&#39;]) ? $_GET[&#39;s&#39;] : 0;
$e = isset($_GET[&#39;e&#39;]) ? $_GET[&#39;e&#39;] : 50;
$count = 85000;
if ($s < $count) {
    $sql = "select * from bac_info where isget =0 order by id desc limit $s,$e ";
    $query = mysql_query($sql);
    while ($rs = mysql_fetch_array($query)) {
        $id = $rs[&#39;id&#39;];
        $sms = $rs[&#39;sms&#39;];
        $typeid = $rs[&#39;typeid&#39;];
        $isget = $rs[&#39;isget&#39;];
        $sql = "insert into bac_info_bak (id,sms,typeid,isget) values(&#39;$id&#39;,&#39;$sms&#39;,&#39;$typeid&#39;,&#39;$isget&#39;)";
        mysql_query($sql);
        echo $sql;
        //exit;
        $sqlu = "update bac_info set isget=1 where id =" . $rs[&#39;id&#39;];
        mysql_query($sqlu);
    }
    echo &#39;<meta http-equiv="refresh" content="0;url=rand.php?s=&#39; . ($s + 50) . &#39;&e=50">正在处理数据,当前为&#39; . $s . &#39;条......&#39;;
} //开源代码phprm.com
else {
    echo &#39;完成所有数据处理 <a href=rand.php>再随机排序一次</a>&#39;;
}
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template