-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbset.php
170 lines (147 loc) · 4.32 KB
/
dbset.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
class DBset{
private $dsn;
private $user;
private $passwd;
private $name1;
private $name2;
private $sex;
private $birth;
private $mail;
private $phone;
private $college;
private $subject;
private $hobby;
private $stat;
public $db;
// construct 用のfunc作る
public function __construct(){
$this->dsn = 'mysql:dbname=Sunseer_BBS; host=localhost; charset=utf8';
$this->user = 'masa';
$this->passwd = 'masa';
// function Use_Session(){
session_start();
//session 呼び出しをここでする
$this->name1 = $_SESSION['name1'];
$this->name2 = $_SESSION['name2'];
$this->sex = $_SESSION['sex'];
$this->birth = $_SESSION['birth'];
$this->mail = $_SESSION['mail'];
$this->phone = $_SESSION['phone'];
$this->college = $_SESSION['college'];
$this->subject = $_SESSION['subject'];
$this->hobby = $_SESSION['hobby'];
}
// connect 用のfunc作る
public function connect(){
try {
var_dump($this->dsn,$this->user,$this->passwd);
$db = new PDO($this->dsn,$this->user,$this->passwd);
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
echo "connect完了<br>";
return $db;
} catch (\PDOException $e) {
echo "connectエラー:{$e->getMessage()}";
}
}
//select 用のfunc作る
public function select(){
try {
$db =$this->connect();
// var_dump($db);
$stat = $db->prepare("SELECT * FROM db_BBS");
$stat->execute();
echo "select完了";
foreach ($stat->fetchAll(PDO::FETCH_ASSOC) as $column => $data){
$column = h($column);
$data = h($data);
echo <<<SHOW
<tr>
<td>$column</td>
<td>$data</td>
</tr>
SHOW;
}
} catch (\PDOException $es) {
echo "selectエラー:{$es->getMessage()}";
}
}
//TODO retrieve用のfuncを作る
public function retrieve($name,$sex,$college,$phone){
$db = $this->connect();
$stat = $db->prepare("SELECT * FROM db_BBS WHERE name ='$name' AND sex = '$sex' AND college = '$college' AND phone ='$phone'");
$stat->execute();
if ($stat->execute() == true) {
}else{
unset($db);
$db = $this->connect();
$stat = $db->prepare("SELECT * FROM db_BBS WHERE name1='$name' OR sex='$sex' OR phone='$phone' OR college='$college' ");
}
}
// insert 用のfunc作る
public function insert(){
try {
$db =$this->connect();
// var_dump($db);
$stat = $db->prepare("INSERT INTO db_BBS(id,name1,name2,sex,birth,mail,phone,college,subject,hobby,icon)
VALUES(:id,:name1,:name2,:sex,:birth,:mail,:phone,:college,:subject,:hobby,:icon)");
$stat->bindValue(':id',NULL);
$stat->bindValue(':name1',$this->name1);
$stat->bindValue(':name2',$this->name2);
$stat->bindValue(':sex',$this->sex);
$stat->bindValue(':birth',$this->birth);
$stat->bindValue(':mail',$this->mail);
$stat->bindValue(':phone',$this->phone);
$stat->bindValue(':college',$this->college);
$stat->bindValue(':subject',$this->subject);
$stat->bindValue(':hobby',$this->hobby);
$stat->bindValue(':icon',"Image/icon.05.42.png");
$stat->execute();
echo "insert完了<br>";
// echo "<br>insert完了<br>";}else{
// echo "エラー";
// }
// $stat->execute();
}catch (\PDOException $ei) {
echo "insertエラー:{$ei->getMessage()}";
}
}
//update 用のfunc作る
public function update(){
try {
$db =$this->connect();
// var_dump($db);
// REVIEW id を中に含める処理をする
$stat = $db->prepare("UPDATE db_BBS SET ???=??? FROM db_BBS WHERE id='$id'");
// TODO SET間の処理をする
$stat->execute();
echo "update完了<br>";
} catch (\PDOException $eu) {
echo "updateエラー:{$eu->getMessage()}";
}
}
//delete 用のfunc作る
public function delete(){
try {
$db =$this->connect();
// var_dump($db);
// REVIEW id を中に含める処理をする
$stat = $db->prepare("DELETE FROM db_BBS WHERE id='$id'" );
$stat->execute();
echo "delete成功";
} catch (\PDOException $ed) {
echo "deleteエラー:{$ed->getMessage()}";
}
}
// TODO 画像upload 用のfuncを作る
//最後の処理に当たる func
public function fin_db(){
session_unset();
session_destroy();
unset($GLOBALS['db']);
unset($db);
// 前のページに飛ぶ
header("Location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/history.php');
}
}
?>