質問編集履歴
1
初心者なりに補足説明を足しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,6 +3,102 @@
|
|
3
3
|
phpからjsonデータの必要な部分だけ取り出して、sqlに一括格納したいです。
|
4
4
|
jsonにするまでには出来ているので、そこまでは略します。
|
5
5
|
|
6
|
+
```tweets.json
|
7
|
+
{
|
8
|
+
"statuses": [
|
9
|
+
{
|
10
|
+
"created_at": "略1",
|
11
|
+
"id": "略1",
|
12
|
+
"id_str": "略1",
|
13
|
+
"text": "#テスト\n略1。",
|
14
|
+
"truncated": false,
|
15
|
+
"entities": {
|
16
|
+
"hashtags": [
|
17
|
+
{
|
18
|
+
"text": "テスト",
|
19
|
+
"indices": [
|
20
|
+
0,
|
21
|
+
7
|
22
|
+
]
|
23
|
+
}
|
24
|
+
],
|
25
|
+
"symbols": [],
|
26
|
+
"user_mentions": [],
|
27
|
+
"urls": []
|
28
|
+
},
|
29
|
+
"metadata": {
|
30
|
+
"iso_language_code": "ja",
|
31
|
+
"result_type": "recent"
|
32
|
+
},
|
33
|
+
"source": "<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Twitter Web App</a>",
|
34
|
+
"in_reply_to_status_id": null,
|
35
|
+
"in_reply_to_status_id_str": null,
|
36
|
+
"in_reply_to_user_id": null,
|
37
|
+
"in_reply_to_user_id_str": null,
|
38
|
+
"in_reply_to_screen_name": null,
|
39
|
+
"user": {
|
40
|
+
"id": "1075985828399046656",
|
41
|
+
"id_str": "1075985828399046656",
|
42
|
+
"name": "略1",
|
43
|
+
"screen_name": "略1",
|
44
|
+
"location": "",
|
45
|
+
"description": "略1",
|
46
|
+
"url": null,
|
47
|
+
"entities": {
|
48
|
+
"description": {
|
49
|
+
"urls": []
|
50
|
+
}
|
51
|
+
}
|
52
|
+
{
|
53
|
+
"created_at": "略2",
|
54
|
+
"id": "1140596976062304256",
|
55
|
+
"id_str": "1140596976062304256",
|
56
|
+
"text": "#テスト/n略2",
|
57
|
+
"truncated": false,
|
58
|
+
"entities": {
|
59
|
+
"hashtags": [
|
60
|
+
{
|
61
|
+
"text": "テスト",
|
62
|
+
"indices": [
|
63
|
+
0,
|
64
|
+
7
|
65
|
+
]
|
66
|
+
}
|
67
|
+
],
|
68
|
+
"symbols": [],
|
69
|
+
"user_mentions": [],
|
70
|
+
"urls": []
|
71
|
+
},
|
72
|
+
"metadata": {
|
73
|
+
"iso_language_code": "ja",
|
74
|
+
"result_type": "recent"
|
75
|
+
},
|
76
|
+
"source": "<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Twitter Web App</a>",
|
77
|
+
"in_reply_to_status_id": null,
|
78
|
+
"in_reply_to_status_id_str": null,
|
79
|
+
"in_reply_to_user_id": null,
|
80
|
+
"in_reply_to_user_id_str": null,
|
81
|
+
"in_reply_to_screen_name": null,
|
82
|
+
"user": {
|
83
|
+
"id": "1075985828399046656",
|
84
|
+
"id_str": "1075985828399046656",
|
85
|
+
"name": "略2",
|
86
|
+
"screen_name": "略2",
|
87
|
+
"location": "",
|
88
|
+
"description": "略2",
|
89
|
+
"url": null,
|
90
|
+
"entities": {
|
91
|
+
"description": {
|
92
|
+
"urls": []
|
93
|
+
}
|
94
|
+
}
|
95
|
+
```
|
96
|
+
|
97
|
+
このようにデータを持っていて(ツイートデータで長いので略してます)、そこから"id","id_str","name","screen_name","text","created_at"の部分をツイート別に格納したいです。↓こんな感じに
|
98
|
+
|id|id_str|name|screen_name|tweets|created_at|
|
99
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
100
|
+
|略1|略1|略1|略1|略1|略1|
|
101
|
+
|略2|略2|略2|略2|略2|略2|
|
6
102
|
### 発生している問題・エラーメッセージ
|
7
103
|
|
8
104
|
```
|
@@ -30,7 +126,7 @@
|
|
30
126
|
for($i=$json_count-1; $i>=0; $i--){
|
31
127
|
$screen_name[] = $json3["statuses"][$i]["user"]["screen_name"];
|
32
128
|
$name[] = $json3["statuses"][$i]["user"]["name"];
|
33
|
-
$
|
129
|
+
$text[] = $json3["statuses"][$i]["text"];
|
34
130
|
$id[] = $json3["statuses"][$i]["id"];
|
35
131
|
$id_str[] = $json3["statuses"][$i]["id_str"];
|
36
132
|
$created_at[] = $json3["statuses"][$i]["created_at"];
|
@@ -49,7 +145,7 @@
|
|
49
145
|
|
50
146
|
$params ='INSERT INTO php_json (id, id_str, name, screen_name, tweets, created_at) VALUES (:id, :id_str, :name, :screen_name, :tweets, :created_at)';
|
51
147
|
$stmt = $sql->prepare($params);
|
52
|
-
$stmt->execute(array(':id'=>$id, ':id_str'=>$id_str, ':name'=>$name, ':screen_name'=>$screen_name, 'tweets'=>$
|
148
|
+
$stmt->execute(array(':id'=>$id, ':id_str'=>$id_str, ':name'=>$name, ':screen_name'=>$screen_name, 'tweets'=>$text, 'created_at'=>$created_at));}
|
53
149
|
|
54
150
|
?>
|
55
151
|
```
|