回答編集履歴
1
追記
test
CHANGED
@@ -11,3 +11,33 @@
|
|
11
11
|
}
|
12
12
|
|
13
13
|
```
|
14
|
+
|
15
|
+
# 追記
|
16
|
+
|
17
|
+
もしくは
|
18
|
+
|
19
|
+
auto_incrementのidカラムを用意し、emailカラムにunique属性をつけておいて
|
20
|
+
|
21
|
+
```SQL
|
22
|
+
|
23
|
+
create table tbl(id int primary key auto_increment,email varchar(30) unique key);
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
IGNOREで投入すれば
|
28
|
+
|
29
|
+
```PHP
|
30
|
+
|
31
|
+
$sql="INSERT IGNORE INTO tbl(email) VALUES(?)";
|
32
|
+
|
33
|
+
$stmt = $pdo->prepare($sql);
|
34
|
+
|
35
|
+
$stmt->execute([$email]);
|
36
|
+
|
37
|
+
if($pdo->lastInsertId()==0){
|
38
|
+
|
39
|
+
//投入できなかった表示
|
40
|
+
|
41
|
+
};
|
42
|
+
|
43
|
+
```
|