Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exception Laravel雄辩的更新失败,但没有';我没有任何例外_Exception_Eloquent_Laravel 5.8 - Fatal编程技术网

Exception Laravel雄辩的更新失败,但没有';我没有任何例外

Exception Laravel雄辩的更新失败,但没有';我没有任何例外,exception,eloquent,laravel-5.8,Exception,Eloquent,Laravel 5.8,经常$bandwidthUpdate->update(['bandwidth'=>$encodedArray])返回false。但我不知道为什么会这样。例外对我不起作用。任何人都知道如何获得未更新的确切原因 下面是数据库结构 $encodedArray = json_encode($existingArray); try { $bandwidthUpdate = ClientBandwidth::where(['c

经常$bandwidthUpdate->update(['bandwidth'=>$encodedArray])返回false。但我不知道为什么会这样。例外对我不起作用。任何人都知道如何获得未更新的确切原因

下面是数据库结构

            $encodedArray = json_encode($existingArray);

            try {
                $bandwidthUpdate = ClientBandwidth::where(['client_id' => $clientId, 'date' => $dateParam]);

                if($bandwidthUpdate->update(['bandwidth' => $encodedArray]))
                {
                    Log::info('bandwidth updated !! '.$dateParam.':::'.'bandwidth type '.$bandwidthType .' Client '.$clientId);
                }else
                {
                    Log::error('bandwidth failed !! '.$dateParam.':::'.'bandwidth type '.$bandwidthType .' Client '.$clientId. ' Refernce '. $refernceKey);
                }

            }
            catch (QueryException $e) {
                Log::error('Exception !! '.$e->getMessage());
                Log::error('Exception !! '.$e->getTraceAsString());
                Log::error('bandwidth update failed !! '.$dateParam.':::'.'bandwidth type '.$bandwidthType .' Client '.$clientId);
            }
            catch (Exception $ex)
            {
                Log::error('Exception !! '.$ex->getMessage());
                Log::error('Exception !! '.$ex->getTraceAsString());
                Log::error('bandwidth failed !! '.$dateParam.':::'.'bandwidth type '.$bandwidthType .' Client '.$clientId);
            }
下面是示例$existingArray,然后将其解析为发送到数据库的json_编码值

CREATE TABLE `client_bandwidth` (
  `id` varchar(64) NOT NULL,
  `client_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `bandwidth` text DEFAULT NULL,
  `total_bandwidth` bigint(20) NOT NULL DEFAULT 0,
  `date` date DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
   PRIMARY KEY (id)
);

“批量更新查询”返回受查询影响的行数,如果成功,则不返回true/false

$bandwidthUpdate->update(['bandwidth'=>$encodedArray])
可以在两种情况下返回
0

  • $bandwidthUpdate
    查询返回了0行
  • 查询返回了行,但未更改任何值
  • 因此,如果您使用相同的
    $encodedArray
    多次运行代码,那么第二点可能会解释为什么每次都得到
    0

    {
        "static": {
            "type": "static",
            "data": {
                "0130": {
                    "hour": "01:30",
                    "bandwidth": "1304802"
                },
                "0215": {
                    "hour": "02:15",
                    "bandwidth": "1794285"
                },
                "0245": {
                    "hour": "02:45",
                    "bandwidth": "534156"
                },
                "0300": {
                    "hour": "03:00",
                    "bandwidth": "4105499"
                },
                "0315": {
                    "hour": "03:15",
                    "bandwidth": "107027"
                },
                "0330": {
                    "hour": "03:30",
                    "bandwidth": "1487364"
                },
                "0430": {
                    "hour": "04:30",
                    "bandwidth": "417"
                },
                "0445": {
                    "hour": "04:45",
                    "bandwidth": "3620927"
                },
                "0500": {
                    "hour": "05:00",
                    "bandwidth": "8820971"
                },
                "0515": {
                    "hour": "05:15",
                    "bandwidth": "40111"
                },
                "0530": {
                    "hour": "05:30",
                    "bandwidth": "1759288"
                },
                "0545": {
                    "hour": "05:45",
                    "bandwidth": "883860"
                },
                "0615": {
                    "hour": "06:15",
                    "bandwidth": "48320"
                },
                "0630": {
                    "hour": "06:30",
                    "bandwidth": "6324949"
                },
                "0645": {
                    "hour": "06:45",
                    "bandwidth": "3543983"
                },
                "0715": {
                    "hour": "07:15",
                    "bandwidth": "7186102"
                },
                "0730": {
                    "hour": "07:30",
                    "bandwidth": "572259"
                },
                "0800": {
                    "hour": "08:00",
                    "bandwidth": "1623099"
                },
                "0815": {
                    "hour": "08:15",
                    "bandwidth": "2898736"
                },
                "0830": {
                    "hour": "08:30",
                    "bandwidth": "1468575"
                },
                "0845": {
                    "hour": "08:45",
                    "bandwidth": "17884836"
                },
                "0900": {
                    "hour": "09:00",
                    "bandwidth": "14234340"
                },
                "0915": {
                    "hour": "09:15",
                    "bandwidth": "10235920"
                },
                "0930": {
                    "hour": "09:30",
                    "bandwidth": "89926519"
                },
                "0945": {
                    "hour": "09:45",
                    "bandwidth": "1352073"
                },
                "1000": {
                    "hour": "10:00",
                    "bandwidth": "901410"
                },
                "1030": {
                    "hour": "10:30",
                    "bandwidth": "55466"
                },
                "1045": {
                    "hour": "10:45",
                    "bandwidth": "2431095"
                },
                "1115": {
                    "hour": "11:15",
                    "bandwidth": "417"
                },
                "1130": {
                    "hour": "11:30",
                    "bandwidth": "1725818"
                },
                "1145": {
                    "hour": "11:45",
                    "bandwidth": "1242887"
                },
                "1300": {
                    "hour": "13:00",
                    "bandwidth": "34994"
                },
                "1330": {
                    "hour": "13:30",
                    "bandwidth": "2914821"
                },
                "1345": {
                    "hour": "13:45",
                    "bandwidth": "1721874"
                },
                "1415": {
                    "hour": "14:15",
                    "bandwidth": "1587430"
                },
                "1430": {
                    "hour": "14:30",
                    "bandwidth": "340454"
                },
                "1630": {
                    "hour": "16:30",
                    "bandwidth": "48017"
                },
                "1700": {
                    "hour": "17:00",
                    "bandwidth": "40867"
                },
                "1730": {
                    "hour": "17:30",
                    "bandwidth": "118178"
                },
                "1800": {
                    "hour": "18:00",
                    "bandwidth": "1328435"
                },
                "1815": {
                    "hour": "18:15",
                    "bandwidth": "2587639"
                },
                "1845": {
                    "hour": "18:45",
                    "bandwidth": "141667"
                },
                "2200": {
                    "hour": "22:00",
                    "bandwidth": "72499"
                }
            },
            "total_bandwidth": 199052386
        },
        "user_agent": {
            "type": "user_agent",
            "data": {
                "0715": {
                    "hour": "07:15",
                    "bandwidth": "1737"
                },
                "0845": {
                    "hour": "08:45",
                    "bandwidth": "3230"
                }
            },
            "total_bandwidth": 4967
        }
    
    }