質問編集履歴
3
エラーの追加と、タイトルなど書き方がよくない点をもろもろ変更しました。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
mysqli_queryで
|
1
|
+
mysqli_queryでvar_dumpした内容が理解できない
|
body
CHANGED
@@ -7,29 +7,95 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
### 発生している問題・エラーメッセージ
|
10
|
-
- mysqli_queryのとき、$this->db_conでエラーが発生している
|
11
|
-
- SELECT,UPDATEともにexecuteメソッドを使うが、UPDATEのみ発生する
|
12
|
-
|
10
|
+
var_dumpした結果の内容がわかっておりません
|
13
11
|
|
14
|
-
|
12
|
+
該当部分(後述のUPDATEのメソッド経由でvar_dump結果の一部)
|
15
13
|
```
|
16
|
-
|
14
|
+
["info"]=> string(40) "Rows matched: 1 Changed: 0 Warnings: 1"
|
17
15
|
```
|
18
16
|
|
19
|
-
|
17
|
+
後述するexecuteメソッド部分が理由で発生している認識です
|
20
18
|
```
|
19
|
+
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
|
20
|
+
```
|
21
|
+
|
22
|
+
var_dumpしている箇所
|
23
|
+
|
24
|
+
```
|
25
|
+
public function execute($sql){
|
26
|
+
$sqli = mysqli_query($this->db_con, $sql);
|
27
|
+
var_dump($this->db_con);
|
28
|
+
return $sqli;
|
29
|
+
}
|
30
|
+
```
|
31
|
+
|
32
|
+
|
33
|
+
SELECTのメソッド経由でのvar_dump結果
|
34
|
+
```
|
35
|
+
object(mysqli)#12 (19) { ["affected_rows"]=> int(1) ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $"
|
36
|
+
["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) ""
|
37
|
+
["error_list"]=> array(0) { } ["field_count"]=> int(22) ["host_info"]=> string(20) "localhost via TCP/IP" ["info"]=> NULL ["insert_id"]=> int(0)
|
38
|
+
["server_info"]=> string(21) "5.5.5-10.1.31-MariaDB" ["server_version"]=> int(50505)
|
39
|
+
["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"
|
40
|
+
["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(199) ["warning_count"]=> int(0) }
|
41
|
+
```
|
42
|
+
|
43
|
+
UPDATEのメソッド経由でのvar_dump結果
|
44
|
+
```
|
21
45
|
object(mysqli)#12 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $"
|
22
|
-
["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) ""
|
46
|
+
["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) ""
|
23
|
-
["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via TCP/IP"
|
24
|
-
["info"]=> string(40) "Rows matched: 1 Changed: 0 Warnings: 1" ["insert_id"]=> int(0)
|
47
|
+
["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)
|
25
48
|
["server_info"]=> string(21) "5.5.5-10.1.31-MariaDB" ["server_version"]=> int(50505)
|
26
|
-
["stat"]=> string(134) "Uptime:
|
49
|
+
["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"
|
27
|
-
["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(
|
50
|
+
["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(203) ["warning_count"]=> int(1) }
|
28
51
|
```
|
29
52
|
|
53
|
+
|
54
|
+
#### SELECTでDatabaseクラスに渡している内容
|
55
|
+
```
|
56
|
+
$data = $db->select('*', 'member', 'mem_id =' . $db->quote($mem_id));
|
57
|
+
|
58
|
+
//$db->quote($mem_id) は定数14にしています
|
59
|
+
```
|
60
|
+
|
61
|
+
#### UPDATEでDatabaseクラスに渡している内容
|
62
|
+
|
63
|
+
下記の$dataArrを$var_dumpした内容
|
64
|
+
```
|
65
|
+
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" }
|
66
|
+
```
|
67
|
+
|
68
|
+
UPDATE部分の内容
|
69
|
+
```
|
70
|
+
case 'update_complete':
|
71
|
+
|
72
|
+
unset($_POST['update_complete']);
|
73
|
+
$dataArr = $_POST;
|
74
|
+
var_dump($dataArr);
|
75
|
+
|
76
|
+
$_POST['traffic'] = implode('_', $_POST['traffic']);
|
77
|
+
$column = '';
|
78
|
+
|
79
|
+
foreach ($dataArr as $key => $value) {
|
80
|
+
if (is_array($value)) {
|
81
|
+
$column .= $key . '=' . "'" . implode('_', $value) . "'" . ',';
|
82
|
+
} else {
|
83
|
+
$column .= $key . '=' . "'" . $value . "'" . ',';
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
$res = $db->update($column . "update_date='11'", 'member',"mem_id=" . $dataArr['mem_id']);
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
|
30
93
|
### 該当のソースコード
|
31
94
|
|
95
|
+
|
96
|
+
Databaseクラス
|
32
|
-
```
|
97
|
+
```
|
98
|
+
|
33
99
|
class Database{
|
34
100
|
|
35
101
|
public $db_con = NULL;
|
@@ -49,8 +115,6 @@
|
|
49
115
|
private function connectDB($db_host, $db_user, $db_pass, $db_name){
|
50
116
|
$tmp_con = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
51
117
|
|
52
|
-
var_dump($this->db_con);
|
53
|
-
|
54
118
|
if($tmp_con !== false){
|
55
119
|
return $tmp_con;
|
56
120
|
}else{
|
@@ -63,7 +127,6 @@
|
|
63
127
|
$sqli = mysqli_query($this->db_con, $sql);
|
64
128
|
var_dump($this->db_con);
|
65
129
|
return $sqli;
|
66
|
-
//return mysqli_query($this->db_con, $sql);
|
67
130
|
}
|
68
131
|
|
69
132
|
public function select($column,$table,$where=''){
|
@@ -96,6 +159,23 @@
|
|
96
159
|
return $data;
|
97
160
|
}
|
98
161
|
|
162
|
+
public function quote($int){
|
163
|
+
return mysqli_real_escape_string($this->db_con, $int);
|
164
|
+
}
|
165
|
+
|
166
|
+
public function str_quote($str){
|
167
|
+
return "'" . mysqli_real_escape_string($this->db_con, $str) . "'";
|
168
|
+
}
|
169
|
+
|
170
|
+
public function getLastId(){
|
171
|
+
return mysqli_insert_id($this->db_con);
|
172
|
+
}
|
173
|
+
|
174
|
+
public function close(){
|
175
|
+
mysqli_close($this->db_con);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
99
179
|
```
|
100
180
|
|
101
181
|
### 補足情報(FW/ツールのバージョンなど)
|
2
誤った部分を修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,13 +11,13 @@
|
|
11
11
|
- SELECT,UPDATEともにexecuteメソッドを使うが、UPDATEのみ発生する
|
12
12
|
- $sql 部分はShellで入力すると動作したため、SQL文法エラーではないはず
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
$tmp_con をvar_dumpした結果
|
15
|
+
```
|
16
16
|
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) }
|
17
17
|
```
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
$this->db_con をvar_dumpした結果
|
20
|
+
```
|
21
21
|
object(mysqli)#12 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $"
|
22
22
|
["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { }
|
23
23
|
["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via TCP/IP"
|
@@ -49,6 +49,8 @@
|
|
49
49
|
private function connectDB($db_host, $db_user, $db_pass, $db_name){
|
50
50
|
$tmp_con = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
51
51
|
|
52
|
+
var_dump($this->db_con);
|
53
|
+
|
52
54
|
if($tmp_con !== false){
|
53
55
|
return $tmp_con;
|
54
56
|
}else{
|
1
var_dumpの結果を追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,7 +11,13 @@
|
|
11
11
|
- SELECT,UPDATEともにexecuteメソッドを使うが、UPDATEのみ発生する
|
12
12
|
- $sql 部分はShellで入力すると動作したため、SQL文法エラーではないはず
|
13
13
|
|
14
|
+
|
15
|
+
```$tmp_con をvar_dumpした結果
|
16
|
+
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) }
|
14
17
|
```
|
18
|
+
|
19
|
+
|
20
|
+
```$this->db_con をvar_dumpした結果
|
15
21
|
object(mysqli)#12 (19) { ["affected_rows"]=> int(0) ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $"
|
16
22
|
["client_version"]=> int(50012) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { }
|
17
23
|
["field_count"]=> int(0) ["host_info"]=> string(20) "localhost via TCP/IP"
|