回答編集履歴

2

調整

2022/09/28 01:05

投稿

yambejp
yambejp

スコア114769

test CHANGED
@@ -3,3 +3,24 @@
3
3
  $names=[1,2,3];
4
4
  echo sprintf('aaa %s bbb',implode(",",array_fill(0,count($names),"?")));
5
5
  ```
6
+
7
+ # 調整版
8
+ ```PHP
9
+ function Hostid_Check(string $start_date, string $end_date){
10
+ $id = array(1001, 1002);
11
+ $data=[];
12
+ $sql ="select hostid from tbl where 1 \n";
13
+ if(count($id)>0){
14
+ $sql.="and hostid in (".implode(",",array_fill(0,count($id),"?")).") \n";
15
+ $data=array_merge($data,$id);
16
+ }
17
+ $sql.="and col between ? and ? \n";
18
+ $data[]=$start_date;
19
+ $data[]=$end_date;
20
+
21
+ $stmt = $pdo->prepare($sql);
22
+ $stmt->execute($data);
23
+ $res = $stmt->fetchAll();
24
+ var_dump($res);
25
+ }
26
+ ```

1

調整

2022/09/27 03:59

投稿

yambejp
yambejp

スコア114769

test CHANGED
@@ -1,4 +1,4 @@
1
- prepare処理を誤解していませんか?
1
+ sprintfやprepare処理を誤解していませんか?
2
2
  ```PHP
3
3
  $names=[1,2,3];
4
4
  echo sprintf('aaa %s bbb',implode(",",array_fill(0,count($names),"?")));