質問編集履歴

1

追加

2020/03/08 08:20

投稿

dato
dato

スコア64

test CHANGED
File without changes
test CHANGED
@@ -62,7 +62,57 @@
62
62
 
63
63
  ?>
64
64
 
65
- ```
65
+ ```
66
+
67
+ function.php ↓
68
+
69
+ ```
70
+
71
+ <?php
72
+
73
+ function e(string $str, string $charset = 'UTF-8'): string {
74
+
75
+ return htmlspecialchars($str, ENT_QUOTES | ENT_HTML5, $charset);
76
+
77
+ }
78
+
79
+
80
+
81
+ function sanitize(array $before): array {
82
+
83
+ foreach($before as $key => $value) {
84
+
85
+ $after[$key] = e($value);
86
+
87
+ }
88
+
89
+ return $after;
90
+
91
+ }
92
+
93
+
94
+
95
+ function dbConnect() {
96
+
97
+ $dsn = "mysql:dbname=ec_site;host=localhost;charset=utf8";
98
+
99
+ $user = "root";
100
+
101
+ $password = "glad";
102
+
103
+
104
+
105
+ $db = new PDO($dsn, $user, $password);
106
+
107
+ $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
108
+
109
+ $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
110
+
111
+ return $db;
112
+
113
+ }
114
+
115
+ ```
66
116
 
67
117
  補足情報(FW/ツールのバージョンなど)
68
118