回答編集履歴

3

見直し

2019/01/16 03:01

投稿

退会済みユーザー
test CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  ```php
4
4
 
5
- $stmt = $pdo -> prepare("INSERT INTO user_table(user,pass,mail) VALUES(:user,:hash,:mail)");
5
+ $stmt = $pdo->prepare("INSERT INTO user_table(user,pass,mail) VALUES(:user,:hash,:mail)");
6
6
 
7
- $stmt -> bindValue(':user', $user, PDO::PARAM_STR);
7
+ $stmt->bindValue(':user', $user, PDO::PARAM_STR);
8
8
 
9
- $stmt -> bindValue(':hash', $hash, PDO::PARAM_STR);
9
+ $stmt->bindValue(':hash', $hash, PDO::PARAM_STR);
10
10
 
11
- $stmt -> bindValue(':mail', $mail, PDO::PARAM_STR);
11
+ $stmt->bindValue(':mail', $mail, PDO::PARAM_STR);
12
12
 
13
13
  ```
14
14
 
@@ -16,14 +16,18 @@
16
16
 
17
17
  ```php
18
18
 
19
- $stmt = $pdo -> prepare("INSERT INTO user_table(user,pass,mail) VALUES(?,?,?)");
19
+ $stmt = $pdo->prepare("INSERT INTO user_table(user,pass,mail) VALUES(?,?,?)");
20
20
 
21
- $stmt -> bindValue(1, $user, PDO::PARAM_STR);
21
+ $stmt->bindValue(1, $user, PDO::PARAM_STR);
22
22
 
23
- $stmt -> bindValue(2, $hash, PDO::PARAM_STR);
23
+ $stmt->bindValue(2, $hash, PDO::PARAM_STR);
24
24
 
25
- $stmt -> bindValue(3, $mail, PDO::PARAM_STR);
25
+ $stmt->bindValue(3, $mail, PDO::PARAM_STR);
26
26
 
27
27
  ```
28
28
 
29
29
  疑問符使うときは、1,2,3などで指定します。
30
+
31
+
32
+
33
+ なお、アロー演算子`->`の前後に空白を入れない書き方の方が一般的。

2

加筆修正

2019/01/16 03:01

投稿

退会済みユーザー
test CHANGED
@@ -1,3 +1,5 @@
1
+ 名前付きプレースホルダで徹底するなら:
2
+
1
3
  ```php
2
4
 
3
5
  $stmt = $pdo -> prepare("INSERT INTO user_table(user,pass,mail) VALUES(:user,:hash,:mail)");
@@ -23,3 +25,5 @@
23
25
  $stmt -> bindValue(3, $mail, PDO::PARAM_STR);
24
26
 
25
27
  ```
28
+
29
+ 疑問符使うときは、1,2,3などで指定します。

1

見直し

2019/01/16 02:59

投稿

退会済みユーザー
test CHANGED
@@ -9,3 +9,17 @@
9
9
  $stmt -> bindValue(':mail', $mail, PDO::PARAM_STR);
10
10
 
11
11
  ```
12
+
13
+ もしくは
14
+
15
+ ```php
16
+
17
+ $stmt = $pdo -> prepare("INSERT INTO user_table(user,pass,mail) VALUES(?,?,?)");
18
+
19
+ $stmt -> bindValue(1, $user, PDO::PARAM_STR);
20
+
21
+ $stmt -> bindValue(2, $hash, PDO::PARAM_STR);
22
+
23
+ $stmt -> bindValue(3, $mail, PDO::PARAM_STR);
24
+
25
+ ```