【问题标题】:Update not working while updating更新时更新不起作用
【发布时间】:2017-05-24 15:23:01
【问题描述】:

在一次更新大约 22000 行的数据库列时,只有 6000 个数据正在更新。它没有显示任何错误!

这是我的代码

for($i=0;$i<=$total/500;$i++)
{
    for($j=0;$j<=500;$j++)
    {

        $patient_id[$i][$j] = $rows[$i * 500 +$j]['patient_id'];
        $total_appointment[$i][$j] = $rows[$i*500+$j]
        ['total_appointments'];


        $this->db->set('no_of_appointment',$total_appointment[$i][$j]); 
        $this->db->where('patient_id',$patient_id[$i][$j]);

        $this->db->update('tbl_patients'); 


    }

}

【问题讨论】:

  • 因为您没有应用任何错误检查代码。我认为执行6000次后执行时间超过错误会出现

标签: php


【解决方案1】:

尝试设置会话超时并增加循环上方的查询执行时间

set_time_limit( 0 );
ini_set('mysql.connect_timeout','7200');
ini_set('max_execution_time', '0');

也许它可以解决你的错误..

【讨论】:

  • 如果您在 php.ini 中更改它,则需要重新启动您的 apache 服务器。以上代码也可以在 .php 文件中使用。
【解决方案2】:

我认为你需要增加mysql.connect_timeout。请检查以下链接以更好地掌握它。 你可以像下面这样增加mysql.connect_timeoutmysql.connect_timeout = 14400。同时增加default_socket_timeout = 14400

ini_set('mysql.connect_timeout', 14400);
ini_set('default_socket_timeout', 14400);

供参考,您可以查看以下链接:
How long does a PHP MySQL database connection remain active?

【讨论】:

    猜你喜欢
    • 2019-11-18
    • 2015-01-19
    • 2022-01-20
    • 1970-01-01
    • 2012-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    相关资源
    最近更新 更多