当前位置:网站首页>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 log articles, binlog log of MySQL log, detailed explanation of binlog log
TSF微服务治理实战系列(一)——治理蓝图
Unity表格配置编辑工具
(Kettle) pdi-ce-8.2 连接MySQL8.x数据库时驱动问题之终极探讨及解决方法分析
Embedded system driver primary [3] - _IO model in character device driver foundation
利用Jenkins实现Unity自动化构建
What is the salary of a software testing student?
符号表
CentOS7 - yum install mysql
在被面试官说了无数次后,终于潜下心来整理了一下JVM的类加载器
随机推荐
EventBus源码分析
FPGA学习笔记——知识点总结
Wwise入门和实战
CentOS7 - yum install mysql
4.3 基于注解的声明式事务和基于XML的声明式事务
《看见新力量》第四期免费下载!走进十五位科技创业者的精彩故事
Unity Visual Effect Graph入门与实践
Do you think border-radius is just rounded corners?【Various angles】
What is the salary of a software testing student?
4.1 JdbcTemplate for declarative transactions
The Road to Ad Monetization for Uni-app Mini Program Apps: Full Screen Video Ads
warning C4251: “std::vector<_Ty>”需要有 dll 接口由 class“Test”的客户端使用错误
OpenGLES 学习之帧缓存
Unity行为树AI分享
【论文阅读笔记】无监督行人重识别中的采样策略
CentOS7 —— yum安装mysql
7.18 Day23----标记语言
npm安装依赖报错npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
7.16 Day22---MYSQL (Dao mode encapsulates JDBC)
利用Jenkins实现Unity自动化构建