douqiaotong8682 2017-08-04 09:00
浏览 37

php脚本返回true突然停止返回值

I have a function in my PHP script which restores data from backup. Everything was fine and working well, until suddenly it stopped working after months of working well. I am using OC 2.2.0 and this function is supposed to restore products and their data from oc_product_backup table. I print_r every step so that I would see where the problem is, and realized that when it gets to:

return true;

it never happens. What could be wrong all of the sudden, and how do I make this work? I never had this kind of problem. My function looks like this:

function restoreBackup()
{
    global $mysqli;

    $i               = 0;
    $getpic          = "SELECT * FROM oc_product_backup LIMIT 0, 100000";
    $backup          = $mysqli->query($getpic);

    $mysqli->autocommit(FALSE); 
    $updateproduct_sql     = "UPDATE oc_product SET image = ?, modified_by = ?, date_modified = ? WHERE product_id= ?";
    $updatedescription_sql = "UPDATE oc_product_description SET meta_description = ?, meta_keyword = ?, tag = ?, modified_by = ? WHERE product_id = ? AND language_id = ?";

    $stmt = $mysqli->prepare($updateproduct_sql);
    $stmt->bind_param('siss', $image, $modified_by, $date_modified, $product_id);
    //print_r ($updateproduct_sql);
    $stmt2 = $mysqli->prepare($updatedescription_sql);
    $stmt2->bind_param('sssisi', $meta_description, $meta_keyword, $tag, $modified_by, $product_id, $language_id);
    //print_r($updatedescription_sql);

    while($row = $backup->fetch_array(MYSQLI_ASSOC))
    {

        //$name              = removeslashes($row['name']);
        //$name              = $row['name'];
        //$description       = removeslashes($row['description']);
        //$description       = $row['description'];
        $meta_description  = $row['meta_description'];
        $meta_keyword      = $row['meta_keyword'];
        $tag               = $row['tag'];
        $product_id        = $row['product_id'];
        $modified_by       = $row['modified_by']; 
        $language_id       = $row['language_id'];
        //if($row['language_id'] == 1)
        //{
        $image          = $row['image'];
        //$ean            = $row['ean'];
        //$name           = $row['name'];
        //$model          = $row['model'];
        //$status         = $row['status'];
        $price_sync     = $row['price_sync'];
        $date_modified  = $row['date_modified']; 

        if(!$stmt->execute())
            return false;

        //}
        if(!$stmt2->execute())
            return false;

        $i++;
        if(($i % 500) === 0) $mysqli->commit();

    }

    $mysqli->commit();
    $backup->close(); //the last line that gets executed
    return true; //this never happens
    writeToLog('- Backup restored');
}
  • 写回答

1条回答 默认 最新

  • duanmu6231 2017-08-04 09:47
    关注

    After looking at the code a bit, it seems like your prepared statements binding the data was outside of the loop, so technically it would never have written any data.

    function restoreBackup() {
        global $mysqli;
    
        $i = 0;
        $getpic = "SELECT * FROM oc_product_backup LIMIT 0, 100000";
        $backup = $mysqli - > query($getpic);
    
        $mysqli - > autocommit(FALSE);
        $updateproduct_sql = "UPDATE oc_product SET image = ?, modified_by = ?, date_modified = ? WHERE product_id= ?";
        $updatedescription_sql = "UPDATE oc_product_description SET meta_description = ?, meta_keyword = ?, tag = ?, modified_by = ? WHERE product_id = ? AND language_id = ?";
    
    
        while ($row = $backup - > fetch_array(MYSQLI_ASSOC)) {
    
            $meta_description = $row['meta_description'];
            $meta_keyword = $row['meta_keyword'];
            $tag = $row['tag'];
            $product_id = $row['product_id'];
            $modified_by = $row['modified_by'];
            $language_id = $row['language_id'];
            $image = $row['image'];
            $price_sync = $row['price_sync'];
            $date_modified = $row['date_modified'];
    
            $stmt = $mysqli - > prepare($updateproduct_sql);
            $stmt - > bind_param('siss', $image, $modified_by, $date_modified, $product_id);
            if (!$stmt - > execute())
                return false;
    
            $stmt2 = $mysqli - > prepare($updatedescription_sql);
            $stmt2 - > bind_param('sssisi', $meta_description, $meta_keyword, $tag, $modified_by, $product_id, $language_id);
            if (!$stmt2 - > execute())
                return false;
    
            $i++;
            if (($i % 500) === 0) $mysqli - > commit();
    
        }
    
        $mysqli - > commit();
        $backup - > close(); //the last line that gets executed
        return true; //this never happens
        writeToLog('- Backup restored');
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答