回答編集履歴

2

修正

2018/07/24 03:48

投稿

yambejp
yambejp

スコア114779

test CHANGED
@@ -40,6 +40,12 @@
40
40
 
41
41
  print_r($rows);
42
42
 
43
+ }catch(PDOException $e){
44
+
45
+ die($e->getMessage());
46
+
47
+ }
48
+
43
49
  ?>
44
50
 
45
51
  <form method="post">
@@ -50,10 +56,6 @@
50
56
 
51
57
  <input type="submit" value="go">
52
58
 
53
- </form>}catch(PDOException $e){
59
+ </form>
54
-
55
- die($e->getMessage());
56
-
57
- }
58
60
 
59
61
  ```

1

修正

2018/07/24 03:48

投稿

yambejp
yambejp

スコア114779

test CHANGED
@@ -16,17 +16,31 @@
16
16
 
17
17
  $sql.="and created_at BETWEEN start = ? AND end = ?";
18
18
 
19
+ $data[]=$start;
20
+
21
+ $data[]=$end;
22
+
19
23
  }
20
24
 
21
25
  print $sql;
22
26
 
23
- $stmt = $pdo->prepare($sql);
27
+ try{
24
28
 
29
+ $dsn = 'mysql:host=localhost; dbname=test1;charset=utf8;';
30
+
31
+ $pdo = new PDO($dsn, $user,$password);
32
+
33
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
34
+
35
+ $stmt = $pdo->prepare($sql);
36
+
25
- $stmt->execute([]);
37
+ $stmt->execute($data);
38
+
39
+ $rows=$stmt->fetchAll(PDO::FETCH_ASSOC);
40
+
41
+ print_r($rows);
26
42
 
27
43
  ?>
28
-
29
-
30
44
 
31
45
  <form method="post">
32
46
 
@@ -36,4 +50,10 @@
36
50
 
37
51
  <input type="submit" value="go">
38
52
 
39
- </form>
53
+ </form>}catch(PDOException $e){
54
+
55
+ die($e->getMessage());
56
+
57
+ }
58
+
59
+ ```