当前位置:网站首页>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);
}
边栏推荐
- 符号表
- MySql数据恢复方法个人总结
- MediaCodec支持的类型
- npm安装依赖报错npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
- 擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
- Tactile intelligent sharing - SSD20X realizes upgrade display progress bar
- 关于C#的反射,你真的运用自如嘛?
- 【问题解决】同一机器上Flask部署TensorRT报错记录
- Teenage Achievement Hackers Need These Skills
- 处理List<Map<String, String>>类型
猜你喜欢
The idea setting recognizes the .sql file type and other file types
《看见新力量》第四期免费下载!走进十五位科技创业者的精彩故事
C language -- operator details
Unity Visual Effect Graph入门与实践
TSF微服务治理实战系列(一)——治理蓝图
C语言 -- 操作符详解
Resolved error: npm WARN config global `--global`, `--local` are deprecated
Unity表格配置编辑工具
npm报错Beginning October 4, 2021, all connections to the npm registry - including for package installa
OpenGLES 学习之帧缓存
随机推荐
利用Jenkins实现Unity自动化构建
Get the selected content of the radio box
7.18 Day23----标记语言
Unity Visual Effect Graph入门与实践
TensorRTx-YOLOv5工程解读(一)
The string class introduction
Do you think border-radius is just rounded corners?【Various angles】
MySQL数据库(基础)
phpexcel导出数据为xml
4.1 JdbcTemplate for declarative transactions
TensorRTx-YOLOv5工程解读(二)
Can 't connect to MySQL server on' localhost3306 '(10061) simple solutions
MySQL log articles, binlog log of MySQL log, detailed explanation of binlog log
Unity DOTS学习教程汇总
3面头条,花7天整理了面试题和学习笔记,已正式入职半个月
5个开源组件管理小技巧
去重的几种方式
The idea setting recognizes the .sql file type and other file types
MySQL database (basic)
4.3 基于注解的声明式事务和基于XML的声明式事务