dsfjnxjlbqv9812 2016-11-22 00:29
浏览 68

循环运行正好20次,但MySql数据库仅插入数据16次

I am developing a parser in which every time the parser will copy an image from URL to remote server, and save the details in MySql database. what i am doing is like this:

function scrap_photo($frompage, $permalink, $url, $message, $createdtime, $type, $imgid) {
    global $last_cron_timestamp;
    global $cxn;

    if ($createdtime > $last_cron_timestamp && $type == "photo") {


            $current_time_stamp = round(microtime(true) * 1000);
            $imgpath = "photo/".$current_time_stamp.".jpg";
            echo $imgpath;
            $fp = fopen($imgpath, "w");

            $handle = curl_init();
            curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
            curl_setopt($handle, CURLOPT_URL, $url);
            curl_setopt($handle, CURLOPT_FOLLOWLOCATION, TRUE);
            curl_setopt($handle, CURLOPT_FAILONERROR, true);
            curl_setopt($handle, CURLOPT_TIMEOUT, 300);
            curl_setopt($handle, CURLOPT_FILE, $fp);
            curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);

            curl_exec($handle);
            curl_close($handle);
            fclose($fp);


            $query = "INSERT INTO images (permalink, url, message, createdtime, imgid, frompage, type, photo_name, photo_path) VALUES ('$permalink', '$url', '$message', '$createdtime', '$imgid', '$frompage', '$type', '$current_time_stamp', '$imgpath')";

            mysqli_query($cxn, $query); 
    }
}

this function 'scrap photo' is being used to save the image to directory and to write the details in DB.

The problem that i am facing is, the loop runs for 20 times, this function is being called 20 times, and even the image count in the folder is 20, but in MySql database, only 16 query is getting inserted.

I can't figure out how or why, help!

  • 写回答

1条回答 默认 最新

  • doujiexi1824 2016-11-22 00:44
    关注
    • Make sure your condition if ($createdtime > $last_cron_timestamp && $type == "photo") { passes for those 20 photos,
    • use mysqli_error to check if database returns errors as for example your values might be null while database doesn't allow them to be null.
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭