使用 json 文件中的数据更新 mysql 表
我对 json 完全陌生,因此很难使用。
我有一个 id 列表存储在 mysql 表的 id 字段中。
例如 id 字段包含这些值
- 100001
- 100002
- 100003
json 文件包含这些 id 的属性,如下所示。
{"100001":{"person":{"name":"John","age":"32,"address":"123 street"}},
{"100002":{"person":{"name":"jenny","age":"22,"address":"100 street"}},
{"100003":{"person":{"name":"james","age":"25,"address":"200 street"}}
我的目的是使用 id 作为 where 子句中的条件,使用 json 文件中的数据更新 mysql 表中的姓名、年龄和地址字段。
但我不知道从哪里开始。
知道他们在做什么的人可以指导我吗?
提前致谢。
I am complete new to json and thefore struggling to work with.
I have a list of id's stored in a id field of a mysql table.
For example id field contains these values
- 100001
- 100002
- 100003
The json file containes properties of these id's, like this.
{"100001":{"person":{"name":"John","age":"32,"address":"123 street"}},
{"100002":{"person":{"name":"jenny","age":"22,"address":"100 street"}},
{"100003":{"person":{"name":"james","age":"25,"address":"200 street"}}
My intention is to update the name, age and address fields in the mysql table with the data in json file using the id as a conditon in the where clause.
But I have no idea where to even start.
Can someone who know's what they doing, please direct me.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你很难理解什么? json_decode() http://php.net/manual/en/function.json- decode.php
将为您提供一个数组,您可以使用 foreach 并创建单独的更新语句或构建一个大型更新语句并执行它。
what you struggling to understand? json_decode() http://php.net/manual/en/function.json-decode.php
that will give you an array you can either foreach though and create separate update statements of build one large update statement and execute it.
你应该在某个地方遇到错误;你的大括号不匹配,并且在年龄之后缺少右引号:
应该是
您缺少实际 ID 的右大括号。为了更容易阅读,请尝试如下格式:
You SHOULD be getting an error somewhere; your curly braces don't match and you're missing closing quotes after the age:
should be
You're missing the closing brace for the actual ID. To make it easier to read, try formatting like this: