回答編集履歴
3
pdo
test
CHANGED
@@ -51,3 +51,73 @@
|
|
51
51
|
それを参考にしてください。
|
52
52
|
|
53
53
|
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# pdo の場合
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
[php-pdo](http://php.net/manual/ja/pdo.construct.php)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
# 公式マニュアルにあるノート
|
70
|
+
|
71
|
+
To connect to the database via a function use this and call the getConnection function in the class constructor.
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
<?php
|
76
|
+
|
77
|
+
class Connection{
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
protected $db;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
public function Connection(){
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
$conn = NULL;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
try{
|
94
|
+
|
95
|
+
$conn = new PDO("mysql:host=localhost;dbname=dbname", "dbuser", "dbpass");
|
96
|
+
|
97
|
+
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
98
|
+
|
99
|
+
} catch(PDOException $e){
|
100
|
+
|
101
|
+
echo 'ERROR: ' . $e->getMessage();
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
$this->db = $conn;
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
public function getConnection(){
|
112
|
+
|
113
|
+
return $this->db;
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
?>
|
122
|
+
|
123
|
+
```
|
2
リンク
test
CHANGED
@@ -32,6 +32,10 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
+
[mysqli_connect](http://php.net/manual/ja/function.mysqli-connect.php)
|
36
|
+
|
37
|
+
|
38
|
+
|
35
39
|
その他
|
36
40
|
|
37
41
|
|
1
変更手順
test
CHANGED
@@ -11,3 +11,39 @@
|
|
11
11
|
mysqli_connect()
|
12
12
|
|
13
13
|
PDO::__construct()
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
# 追記
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
```diff
|
26
|
+
|
27
|
+
-mysql_connect(/*connection args*/)
|
28
|
+
|
29
|
+
+mysqli_connect(/*connection args*/)
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
その他
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
mysql_ も mysqli_ に置き換えてください。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
一部動かない(存在しない)と言われたメソッドは
|
44
|
+
|
45
|
+
マニュアルにどのメソッドに変えればいいかが書いてあるため
|
46
|
+
|
47
|
+
それを参考にしてください。
|
48
|
+
|
49
|
+
|