質問編集履歴
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,10 +9,6 @@
|
|
9
9
|
// INSERT, DELETE, UPDATE の共通処理
|
10
10
|
function apply_row( $type, $args ){
|
11
11
|
$result = [];
|
12
|
-
|
13
|
-
$id = $args['id'];
|
14
|
-
$name = $args['name'];
|
15
|
-
$age = $args['age'];
|
16
12
|
|
17
13
|
// INSERT
|
18
14
|
if ( $type === 'insert' ) {
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,7 +46,7 @@
|
|
46
46
|
}
|
47
47
|
|
48
48
|
// INSERTを実行
|
49
|
-
$args = ['
|
49
|
+
$args = ['name'=>'a','age'=>20];
|
50
50
|
$result = apply_row( 'insert', $args );
|
51
51
|
```
|
52
52
|
### 試したクラス
|
@@ -88,7 +88,7 @@
|
|
88
88
|
}
|
89
89
|
|
90
90
|
// INSERTを実行
|
91
|
-
$args = ['
|
91
|
+
$args = ['name'=>'a','age'=>20];
|
92
92
|
$insert_row = new insert_row( $args );
|
93
93
|
$insert_row->apply();
|
94
94
|
```
|
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
|
33
33
|
// INSERT
|
34
34
|
function insert_row( $args ){
|
35
|
-
$sql = "INSERT INTO tbl (name, age) VALUES ($name, $age);";
|
35
|
+
$sql = "INSERT INTO tbl (name, age) VALUES ($args['name'], $args['age']);";
|
36
36
|
}
|
37
37
|
|
38
38
|
// DELETE
|
1
訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,17 +16,33 @@
|
|
16
16
|
|
17
17
|
// INSERT
|
18
18
|
if ( $type === 'insert' ) {
|
19
|
-
$s
|
19
|
+
$result = insert_row( $args );
|
20
20
|
|
21
21
|
// DELETE
|
22
22
|
} else if ( $type === 'delete' ) {
|
23
|
-
|
23
|
+
$result = delete_row( $args );
|
24
|
+
|
24
25
|
// UPDATE
|
25
26
|
} else if ( $type === 'update' ) {
|
26
|
-
|
27
|
+
$result = update_row( $args );
|
27
28
|
}
|
28
29
|
|
29
30
|
return $result;
|
31
|
+
}
|
32
|
+
|
33
|
+
// INSERT
|
34
|
+
function insert_row( $args ){
|
35
|
+
$sql = "INSERT INTO tbl (name, age) VALUES ($name, $age);";
|
36
|
+
}
|
37
|
+
|
38
|
+
// DELETE
|
39
|
+
function delete_row( $args ){
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
// UPDATE
|
44
|
+
function update_row( $args ){
|
45
|
+
|
30
46
|
}
|
31
47
|
|
32
48
|
// INSERTを実行
|
@@ -35,7 +51,7 @@
|
|
35
51
|
```
|
36
52
|
### 試したクラス
|
37
53
|
上記の関数に対し、[ある方から「クラスを使うべし」とアドバイスを頂きました](https://teratail.com/questions/p48zgc0ac22qmg)。
|
38
|
-
そこで初めてクラスを調べ、上記関数
|
54
|
+
そこで初めてクラスを調べ、上記関数と同じ動作を実現するクラスを書けたかと思います。
|
39
55
|
```php
|
40
56
|
// INSERT, DELETE, UPDATE の共通処理
|
41
57
|
class apply_row {
|