質問編集履歴
3
エラーの追加と、タイトルなど書き方がよくない点をもろもろ変更しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
mysqli_queryで
|
1
|
+
mysqli_queryでvar_dumpした内容が理解できない
|
test
CHANGED
@@ -16,43 +16,169 @@
|
|
16
16
|
|
17
17
|
### 発生している問題・エラーメッセージ
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
```
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
19
|
+
var_dumpした結果の内容がわかっておりません
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
該当部分(後述のUPDATEのメソッド経由でvar_dump結果の一部)
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
["info"]=> string(40) "Rows matched: 1 Changed: 0 Warnings: 1"
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
後述するexecuteメソッド部分が理由で発生している認識です
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\member\lib\Database.class.php on line 62
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
var_dumpしている箇所
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
public function execute($sql){
|
50
|
+
|
51
|
+
$sqli = mysqli_query($this->db_con, $sql);
|
52
|
+
|
53
|
+
var_dump($this->db_con);
|
54
|
+
|
55
|
+
return $sqli;
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
SELECTのメソッド経由でのvar_dump結果
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
object(mysqli)#12 (19) { ["affected_rows"]=> int(1) ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $"
|
70
|
+
|
71
|
+
["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) ""
|
72
|
+
|
73
|
+
["error_list"]=> array(0) { } ["field_count"]=> int(22) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0)
|
74
|
+
|
75
|
+
["server_info"]=> string(21) "5.5.5-10.1.31-MariaDB" ["server_version"]=> int(50505)
|
76
|
+
|
77
|
+
["stat"]=> string(134) "Uptime: 28284 Threads: 2 Questions: 545 Slow queries: 0 Opens: 26 Flush tables: 1 Open tables: 20 Queries per second avg: 0.019"
|
78
|
+
|
79
|
+
["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(199) ["warning_count"]=> int(0) }
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
UPDATEのメソッド経由でのvar_dump結果
|
38
86
|
|
39
87
|
```
|
40
88
|
|
41
89
|
object(mysqli)#12 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $"
|
42
90
|
|
43
|
-
["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) ""
|
91
|
+
["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) ""
|
44
|
-
|
45
|
-
|
92
|
+
|
46
|
-
|
47
|
-
["info"]=> string(40) "Rows matched: 1 Changed: 0 Warnings: 1" ["insert_id"]=> int(0)
|
93
|
+
["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> string(40) "Rows matched: 1 Changed: 0 Warnings: 1" ["insert_id"]=> int(0)
|
48
94
|
|
49
95
|
["server_info"]=> string(21) "5.5.5-10.1.31-MariaDB" ["server_version"]=> int(50505)
|
50
96
|
|
51
|
-
["stat"]=> string(134) "Uptime: 2
|
52
|
-
|
53
|
-
["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(
|
54
|
-
|
55
|
-
```
|
97
|
+
["stat"]=> string(134) "Uptime: 28375 Threads: 2 Questions: 551 Slow queries: 0 Opens: 26 Flush tables: 1 Open tables: 20 Queries per second avg: 0.019"
|
98
|
+
|
99
|
+
["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(203) ["warning_count"]=> int(1) }
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
#### SELECTでDatabaseクラスに渡している内容
|
108
|
+
|
109
|
+
```
|
110
|
+
|
111
|
+
$data = $db->select('*', 'member', 'mem_id =' . $db->quote($mem_id));
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
//$db->quote($mem_id) は定数14にしています
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
#### UPDATEでDatabaseクラスに渡している内容
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
下記の$dataArrを$var_dumpした内容
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
array(18) { ["family_name"]=> string(6) "捕鯨" ["first_name"]=> string(6) "太郎" ["family_name_kana"]=> string(9) "ほげい" ["first_name_kana"]=> string(12) "いちろう" ["sex"]=> string(1) "1" ["year"]=> string(4) "1948" ["month"]=> string(2) "08" ["day"]=> string(2) "01" ["zip1"]=> string(3) "110" ["zip2"]=> string(4) "0003" ["address"]=> string(24) "東京都台東区根岸" ["email"]=> string(14) "hoge@gmail.com" ["tel1"]=> string(3) "090" ["tel2"]=> string(4) "0000" ["tel3"]=> string(4) "1111" ["traffic"]=> array(2) { [0]=> string(1) "0" [1]=> string(1) "4" } ["contents"]=> string(0) "" ["mem_id"]=> string(2) "14" }
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
UPDATE部分の内容
|
136
|
+
|
137
|
+
```
|
138
|
+
|
139
|
+
case 'update_complete':
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
unset($_POST['update_complete']);
|
144
|
+
|
145
|
+
$dataArr = $_POST;
|
146
|
+
|
147
|
+
var_dump($dataArr);
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
$_POST['traffic'] = implode('_', $_POST['traffic']);
|
152
|
+
|
153
|
+
$column = '';
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
foreach ($dataArr as $key => $value) {
|
158
|
+
|
159
|
+
if (is_array($value)) {
|
160
|
+
|
161
|
+
$column .= $key . '=' . "'" . implode('_', $value) . "'" . ',';
|
162
|
+
|
163
|
+
} else {
|
164
|
+
|
165
|
+
$column .= $key . '=' . "'" . $value . "'" . ',';
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
$res = $db->update($column . "update_date='11'", 'member',"mem_id=" . $dataArr['mem_id']);
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
```
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
56
182
|
|
57
183
|
|
58
184
|
|
@@ -60,7 +186,13 @@
|
|
60
186
|
|
61
187
|
|
62
188
|
|
189
|
+
|
190
|
+
|
191
|
+
Databaseクラス
|
192
|
+
|
63
|
-
```
|
193
|
+
```
|
194
|
+
|
195
|
+
|
64
196
|
|
65
197
|
class Database{
|
66
198
|
|
@@ -100,49 +232,73 @@
|
|
100
232
|
|
101
233
|
|
102
234
|
|
235
|
+
if($tmp_con !== false){
|
236
|
+
|
237
|
+
return $tmp_con;
|
238
|
+
|
239
|
+
}else{
|
240
|
+
|
241
|
+
printf("Connect failed: %s\n", mysqli_connect_error());
|
242
|
+
|
243
|
+
exit();
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
public function execute($sql){
|
252
|
+
|
253
|
+
$sqli = mysqli_query($this->db_con, $sql);
|
254
|
+
|
103
255
|
var_dump($this->db_con);
|
104
256
|
|
105
|
-
|
106
|
-
|
107
|
-
if($tmp_con !== false){
|
108
|
-
|
109
|
-
|
257
|
+
return $sqli;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
public function select($column,$table,$where=''){
|
264
|
+
|
265
|
+
if($where === ''){
|
266
|
+
|
267
|
+
$sql = ' SELECT ' . $column . ' FROM ' . $table;
|
110
268
|
|
111
269
|
}else{
|
112
270
|
|
113
|
-
|
271
|
+
$sql = ' SELECT ' . $column . ' FROM ' . $table . ' WHERE ' .$where;
|
114
|
-
|
115
|
-
|
272
|
+
|
116
|
-
|
117
|
-
}
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
118
|
-
|
277
|
+
$res = $this->execute($sql);
|
278
|
+
|
279
|
+
$data = [];
|
280
|
+
|
281
|
+
while ($row = mysqli_fetch_array($res)){
|
282
|
+
|
283
|
+
array_push($data, $row);
|
284
|
+
|
119
|
-
}
|
285
|
+
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
286
|
+
|
124
|
-
|
125
|
-
$sqli = mysqli_query($this->db_con, $sql);
|
126
|
-
|
127
|
-
var_dump($this->db_con);
|
128
|
-
|
129
|
-
return $
|
287
|
+
return $data;
|
130
|
-
|
131
|
-
|
288
|
+
|
132
|
-
|
133
|
-
}
|
289
|
+
}
|
134
|
-
|
135
|
-
|
136
|
-
|
290
|
+
|
291
|
+
|
292
|
+
|
137
|
-
public function
|
293
|
+
public function update($column,$table,$where=''){
|
138
294
|
|
139
295
|
if($where === ''){
|
140
296
|
|
141
|
-
$sql = '
|
297
|
+
$sql = ' UPDATE ' . $table . ' SET ' . $column;
|
142
298
|
|
143
299
|
}else{
|
144
300
|
|
145
|
-
$sql = '
|
301
|
+
$sql = ' UPDATE ' . $table . ' SET ' . $column . ' WHERE ' . $where;
|
146
302
|
|
147
303
|
}
|
148
304
|
|
@@ -164,33 +320,37 @@
|
|
164
320
|
|
165
321
|
|
166
322
|
|
167
|
-
public function u
|
323
|
+
public function quote($int){
|
168
|
-
|
169
|
-
|
324
|
+
|
170
|
-
|
171
|
-
|
325
|
+
return mysqli_real_escape_string($this->db_con, $int);
|
172
|
-
|
173
|
-
|
326
|
+
|
174
|
-
|
175
|
-
$sql = ' UPDATE ' . $table . ' SET ' . $column . ' WHERE ' . $where;
|
176
|
-
|
177
|
-
|
327
|
+
}
|
178
|
-
|
179
|
-
|
180
|
-
|
328
|
+
|
329
|
+
|
330
|
+
|
181
|
-
|
331
|
+
public function str_quote($str){
|
182
|
-
|
183
|
-
|
332
|
+
|
184
|
-
|
185
|
-
|
333
|
+
return "'" . mysqli_real_escape_string($this->db_con, $str) . "'";
|
186
|
-
|
187
|
-
|
334
|
+
|
188
|
-
|
189
|
-
|
335
|
+
}
|
190
|
-
|
336
|
+
|
337
|
+
|
338
|
+
|
191
|
-
|
339
|
+
public function getLastId(){
|
340
|
+
|
192
|
-
|
341
|
+
return mysqli_insert_id($this->db_con);
|
342
|
+
|
193
|
-
}
|
343
|
+
}
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
public function close(){
|
348
|
+
|
349
|
+
mysqli_close($this->db_con);
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
}
|
194
354
|
|
195
355
|
|
196
356
|
|
2
誤った部分を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,9 +24,9 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
$tmp_con をvar_dumpした結果
|
28
|
+
|
29
|
+
```
|
30
30
|
|
31
31
|
object(mysqli)#12 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $" ["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(21) "5.5.5-10.1.31-MariaDB" ["server_version"]=> int(50505) ["stat"]=> string(134) "Uptime: 25793 Threads: 2 Questions: 517 Slow queries: 0 Opens: 26 Flush tables: 1 Open tables: 20 Queries per second avg: 0.020" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(184) ["warning_count"]=> int(0) }
|
32
32
|
|
@@ -34,9 +34,9 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
$this->db_con をvar_dumpした結果
|
38
|
+
|
39
|
+
```
|
40
40
|
|
41
41
|
object(mysqli)#12 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $"
|
42
42
|
|
@@ -100,6 +100,10 @@
|
|
100
100
|
|
101
101
|
|
102
102
|
|
103
|
+
var_dump($this->db_con);
|
104
|
+
|
105
|
+
|
106
|
+
|
103
107
|
if($tmp_con !== false){
|
104
108
|
|
105
109
|
return $tmp_con;
|
1
var_dumpの結果を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,8 +24,20 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
+
|
28
|
+
|
29
|
+
```$tmp_con をvar_dumpした結果
|
30
|
+
|
31
|
+
object(mysqli)#12 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $" ["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(21) "5.5.5-10.1.31-MariaDB" ["server_version"]=> int(50505) ["stat"]=> string(134) "Uptime: 25793 Threads: 2 Questions: 517 Slow queries: 0 Opens: 26 Flush tables: 1 Open tables: 20 Queries per second avg: 0.020" ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(184) ["warning_count"]=> int(0) }
|
32
|
+
|
27
33
|
```
|
28
34
|
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
```$this->db_con をvar_dumpした結果
|
40
|
+
|
29
41
|
object(mysqli)#12 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $"
|
30
42
|
|
31
43
|
["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { }
|