-
Notifications
You must be signed in to change notification settings - Fork 1
/
koneksi.php
194 lines (175 loc) · 6.59 KB
/
koneksi.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
class database
{
// disini butuh host
public $host = "localhost",
$username = "root",
$pass = "",
$db = "pkl",
$koneksi;
public function __construct()
{
$this->koneksi = new mysqli($this->host, $this->username, $this->pass, $this->db);
if ($this->koneksi->connect_errno) {
echo "Database Tidak Ada....!";
exit;
}
}
public function register($username, $password, $nama)
{
$insert = mysqli_query($this->koneksi, "insert into admin values ('','$username','$password','$nama')");
return $insert;
}
public function login($username, $password, $remember)
{
$query = mysqli_query($this->koneksi, "select * from admin where username='$username' ");
$data_user = $query->fetch_array();
if (password_verify($password, $data_user['password'])) {
if ($remember) {
setcookie('username', $username, time() + (60 * 60 * 24 * 5), '/');
setcookie('nama', $data_user['nama'], time() + (60 * 60 * 24 * 5), '/');
}
$_SESSION['username'] = $username;
$_SESSION['nama'] = $data_user['nama'];
$_SESSION['is_login'] = true;
return true;
} else {
header("location:login.php?pesan=gagal");
}
}
public function relogin($username)
{
$query = mysqli_query($this->koneksi, "select * from admin where username='$username'");
$data_user = $query->fetch_array();
$_SESSION['username'] = $username;
$_SESSION['nama'] = $data_user['nama'];
$_SESSION['is_login'] = true;
}
public function tampil_data($data)
{
$data = "SELECT ind.`nib`, pm.`nama`, ind.`namaind`, ind.`namaproduk`, ind.`tahun`, ind.`pendthn`,ind.`inthn`,ind.`pekerja`, ind.`alamatind`, pm.`sosmed`,pm.`telp`, kec.`namakec`
FROM industri ind, pemilik pm, kecamatan kec
WHERE ind.`nib` = pm.`nib`
AND ind.`id_kec` = kec.`id_kec`";
$hasil = $this->koneksi->query($data);
while ($d = mysqli_fetch_array($hasil)) {
$result[] = $d;
}
return $result;
}
public function tampil_kec()
{
$data = "SELECT * FROM kecamatan ORDER BY namakec ASC";
$hasil = $this->koneksi->query($data);
while ($d = mysqli_fetch_array($hasil)) {
$result[] = $d;
}
return $result;
}
public function tampil_data1()
{
$data = "SELECT pm.`nama`, ind.`namaind`, ind.`namaproduk`,ind.`tahun`,ind.`pendthn`,ind.`inthn`, ind.`pekerja`, ind.`alamatind`, pm.`sosmed`, kec.`namakec`
FROM industri ind, pemilik pm, kecamatan kec
WHERE ind.`nib` = pm.`nib`
AND ind.`id_kec` = kec.`id_kec` ORDER BY namakec ASC ";
$hasil = $this->koneksi->query($data);
while ($d = mysqli_fetch_array($hasil)) {
$result[] = $d;
}
return $result;
}
// INSERT DATA
public function input(
$nib,
$namaind,
$namaproduk,
$tahun,
$pendthn,
$inthn,
$pekerja,
$alamatind,
$nik,
$nama,
$email,
$alamat,
$sosmed,
$telp,
$inputkec
) {
$simpan1 = "insert into industri(nib, namaind, namaproduk, tahun, pendthn ,inthn, pekerja, alamatind, id_kec) values('$nib', '$namaind', '$namaproduk', '$tahun', '$pendthn','$inthn', '$pekerja', '$alamatind', '$inputkec');";
$simpan2 = "insert into pemilik(nik, nama, email, alamat, sosmed,telp, nib) values('$nik', '$nama', '$email', '$alamat', '$sosmed','$telp', '$nib');";
$hasil = $this->koneksi->query($simpan1);
$hasil = $this->koneksi->query($simpan2);
}
// DELETE DATA
public function hps_ind($nib)
{
$simpan = "delete from industri where nib = '$nib'";
$hasil = $this->koneksi->query($simpan);
}
public function hps_pm($nik)
{
$simpan = "delete from pemilik where nik = '$nik'";
$hasil = $this->koneksi->query($simpan);
}
//edit
public function edit($nib)
{
$data = "SELECT ind.`nib`, pm.`nik`, pm.`nama`, ind.`namaind`, ind.`namaproduk`, ind.`tahun`, ind.`pendthn`, ind.`inthn`, ind.`pekerja`,
ind.`alamatind`, pm.`alamat`, pm.`email`, pm.`sosmed`,pm.`telp`, kec.`namakec`
FROM industri ind, pemilik pm, kecamatan kec
WHERE ind.`nib` = pm.`nib`
AND ind.`id_kec` = kec.`id_kec`
AND ind.`nib` = $nib AND pm.`nib` = $nib";
$hasil = $this->koneksi->query($data);
while ($d = mysqli_fetch_array($hasil)) {
$result[] = $d;
}
return $result;
}
//update
public function update(
$nib,
$nik,
$nama,
$namaind,
$namaproduk,
$tahun,
$pendthn,
$inthn,
$pekerja,
$alamatind,
$email,
$alamat,
$sosmed,
$telp,
$inputkec
) {
$simpan1 = "UPDATE industri SET namaind='$namaind', namaproduk='$namaproduk', tahun = '$tahun', pendthn = '$pendthn', inthn = '$inthn', pekerja = '$pekerja', alamatind = '$alamatind', id_kec ='$inputkec' WHERE nib='$nib'";
$simpan2 = "UPDATE pemilik SET nik = '$nik', nama = '$nama', email = '$email', alamat = '$alamat', sosmed = '$sosmed', telp = '$telp' WHERE nib='$nib'";
$hasil1 = $this->koneksi->query($simpan1);
$hasil2 = $this->koneksi->query($simpan2);
}
// function cari($kec,$thn){
// $data = mysql_query("SELECT ind.`nib`, pm.`nama`, ind.`namaind`, ind.`namaproduk`, ind.`tahun`, ind.`pendthn`, ind.`inthn`, ind.`pekerja`,
// ind.`alamatind`, pm.`sosmed`,pm.`telp`, kec.`namakec`
// FROM industri ind, pemilik pm, kecamatan kec
// WHERE ind.`nib` = pm.`nib`
// AND ind.`id_kec` = kec.`id_kec` where ind.id_kec ='$kec' and ind.tahun='$thn' ");
// $hasil = $this->koneksi->query($data);
// while ($d = mysqli_fetch_array($hasil))
// {
// $result[] = $d;
// }
// return $result;
// }
// <?php
// if(isset($_GET['cari'])){
// $cari = $_GET['cari'];
// $data = mysql_query("select * from mhs where nama like '%".$cari."%'");
// }else{
// $data = mysql_query("select * from mhs");
// }
// $no = 1;
// while($d = mysql_fetch_array($data)){
}