当前位置:网站首页>php将多维数据保存进json文件
php将多维数据保存进json文件
2022-08-04 05:25:00 【eleven_-11】
/**
* @description 将任务信息保存到json文件中
*
* @param string $filename
*
* @return bool
* @throws MYS_RuntimeEvent
*/
public function saveToJson($filename) {
/**
* 1. JSON数据的格式如下
*"RestoreOrder": {
* "timeStamp": "2016-12-28 14:03:50",
* "isChecked":"",
* "dataSaved":"",
* "dataSure":"",
* "hostIp":"",
* "hostUUID":""
* "inst": {
* "inst1": {
* "db1": {
* "dbname":""
* "isRestore":"",
* "inst_name": "",
* "inst_port": "",
* "des_port": "",
* "des_path": "",
* "des_connect": {
* "user" : "",
* "key" : "",
* "connect_ip" : "",
* }
* },
* "db2": {...}
* },
* "inst2": {...}
* }
* }
*};
* 2. 有些数据需要从数据库中查询获得
*
* 3.$task的数据
* $temp_data = array(
* "dbname" => $this->timestamp,
* "isRestore" => $this->ischecked,
* "inst_name" => $this->datasaved,
* "inst_port" => $this->datasure,
* "des_port" => $this->hostip,
* "des_path" => $this->uuid
);
*/
if (!$this->OrderValid) {
throw new MYS_RuntimeEvent(MYS_Severity::SEVERITY_EMERGENCY,
OBJECT_PARAM_INVALID, __CLASS__ . ":" . __FUNCTION__, __LINE__);
}
// 创建json数据
$temp_data = array(
"timeStamp" => $this->timestamp,
"isChecked" => $this->ischecked,
"dataSaved" => $this->datasaved,
"dataSure" => $this->datasure,
"hostIp" => $this->hostip,
"hostUUID" => $this->uuid
);
// 创建恢复任务对象信息
foreach ($this->tasklist as $task) {
$instconnect = $task['des_connect'];
$arr_auth = $instconnect->getAuthenticationArr();
$arr_conn = $instconnect->getConnectionArr();
unset($task['isRestore']);
unset($task['instconnect']);
$temp_data['inst'][$task['inst_name']][$task['dbname']] = $task;
$temp_data['inst'][$task['inst_name']][$task['dbname']]['des_connect'] =
array(
"user" => $arr_auth['UID'],
"key" => $arr_auth['PWD'],
"connect_ip" => $arr_conn['HOST'],
);
$temp_data['inst'][$task['inst_name']][$task['dbname']]['isRestore'] =
$this->isrestore[$task['inst_name']][$task['dbname']];
}
// 保存到文件中
file_put_contents(dirname(__FILE__) . "/../" . MYSQLTaskRSController::TMPTASKSHADOWRS_LOCK, json_encode($temp_data));
copy(dirname(__FILE__) . "/../" . MYSQLTaskRSController::TMPTASKSHADOWRS_LOCK, $filename);
}
边栏推荐
猜你喜欢
Resolved error: npm WARN config global `--global`, `--local` are deprecated
FPGA学习笔记——知识点总结
[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection
MySQL database (basic)
DP4398:国产兼容替代CS4398立体声24位/192kHz音频解码芯片
Programming hodgepodge (4)
Unity动画生成工具
OpenGLES 学习之帧缓存
Delphi-C端有趣的菜单操作界面设计
8.03 Day34---BaseMapper query statement usage
随机推荐
编程大杂烩(三)
12. Paging plugin
Tactile intelligent sharing - SSD20X realizes upgrade display progress bar
The symbol table
Plus版SBOM:流水线物料清单PBOM
Sublime Text 3 2021.8.3 个人配置
企业需要知道的5个 IAM 最佳实践
[Cocos 3.5.2]开启模型合批
The Road to Ad Monetization for Uni-app Mini Program Apps: Full Screen Video Ads
Dynamic programming of the division of numbers
Unity行为树AI分享
FLV格式详解
4.3 Annotation-based declarative transactions and XML-based declarative transactions
MediaCodec支持的类型
音视频相关基础知识与FFmpeg介绍
力扣:63. 不同路径 II
编程大杂烩(四)
word 公式编辑器 键入技巧 | 写数学作业必备速查表
OpenGLES 学习之帧缓存
高性能高可靠性高扩展性分布式防火墙架构