回答編集履歴

5

modified

2019/05/03 07:00

投稿

mpyw
mpyw

スコア5223

test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  implode(', ', array_fill_keys(array_keys($array), '?'))
30
30
 
31
- ;
31
+ );
32
32
 
33
33
 
34
34
 
@@ -82,7 +82,7 @@
82
82
 
83
83
  implode(', ', array_fill_keys(array_keys($array), '?'))
84
84
 
85
- ;
85
+ );
86
86
 
87
87
 
88
88
 

4

modified

2019/05/03 07:00

投稿

mpyw
mpyw

スコア5223

test CHANGED
@@ -49,3 +49,57 @@
49
49
  }
50
50
 
51
51
  ```
52
+
53
+
54
+
55
+ どちらかと言うとオブジェクト指向型のほうがおすすめです。手続き型は関数名が長すぎてうんざり…
56
+
57
+
58
+
59
+ ```php
60
+
61
+ <?php
62
+
63
+
64
+
65
+ $user = 'user';
66
+
67
+ $array = ['foo', 'bar', 'baz'];
68
+
69
+
70
+
71
+ $query = sprintf(
72
+
73
+ '
74
+
75
+ select * from
76
+
77
+ left join skip on joblist.awuser = skip.awuser
78
+
79
+ where (user != ? or user is null) and job in (%s)
80
+
81
+ ',
82
+
83
+ implode(', ', array_fill_keys(array_keys($array), '?'))
84
+
85
+ ;
86
+
87
+
88
+
89
+ $stmt = $connection->prepare($query);
90
+
91
+ $stmt->bind_param('s' . str_repeat('s', count($array)), $user, ...$array);
92
+
93
+ $stmt->execute();
94
+
95
+ $result = $stmt->get_result();
96
+
97
+
98
+
99
+ while ($row = $result->fetch_array()) {
100
+
101
+ /* ... */
102
+
103
+ }
104
+
105
+ ```

3

修正

2019/05/03 06:59

投稿

mpyw
mpyw

スコア5223

test CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
 
34
34
 
35
- $stmt = mysqli_prepare($query);
35
+ $stmt = mysqli_prepare($connection, $query);
36
36
 
37
37
  mysqli_stmt_bind_param($stmt, 's' . str_repeat('s', count($array)), $user, ...$array);
38
38
 

2

modified

2019/05/03 06:57

投稿

mpyw
mpyw

スコア5223

test CHANGED
@@ -38,8 +38,6 @@
38
38
 
39
39
  mysqli_stmt_execute($stmt);
40
40
 
41
-
42
-
43
41
  $result = mysqli_stmt_get_result($stmt);
44
42
 
45
43
 

1

修正

2019/05/03 06:56

投稿

mpyw
mpyw

スコア5223

test CHANGED
@@ -32,7 +32,9 @@
32
32
 
33
33
 
34
34
 
35
+ $stmt = mysqli_prepare($query);
36
+
35
- mysqli_stmt_bind_param($query, 's' . str_repeat('s', count($array)), $user, ...$array);
37
+ mysqli_stmt_bind_param($stmt, 's' . str_repeat('s', count($array)), $user, ...$array);
36
38
 
37
39
  mysqli_stmt_execute($stmt);
38
40