Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
PSW2-D3TI01
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julius Samosir
PSW2-D3TI01
Commits
b8d5bb09
Commit
b8d5bb09
authored
Jun 06, 2020
by
Julius Samosir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
06c1bfeb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
226 additions
and
0 deletions
+226
-0
database.php
common/database.php
+226
-0
No files found.
common/database.php
0 → 100644
View file @
b8d5bb09
<?php
session_start
();
global
$db
;
$db
=
mysqli_connect
(
'localhost'
,
'root'
,
''
,
'proyek_psw'
);
if
(
!
$db
){
die
(
"Database Connect Problem"
);
}
function
ExecuteQuery
(
$query
){
global
$db
;
$result
=
mysqli_query
(
$db
,
$query
);
return
$result
;
}
function
query
(
$query
){
global
$db
;
$result
=
mysqli_query
(
$db
,
$query
);
$rows
=
[];
while
(
$row
=
mysqli_fetch_assoc
(
$result
))
{
$rows
[]
=
$row
;
}
return
$rows
;
}
function
LoginAccount
(
$username
,
$password
){
$query
=
"SELECT * FROM akun WHERE username='
$username
' AND password='
$password
'"
;
$user
=
ExecuteQuery
(
$query
);
return
$user
;
}
function
redirect
(
$_location
)
{
header
(
'Location: '
.
$_location
);
}
function
CekAkun
(
$username
){
$query
=
"SELECT username FROM akun WHERE username ='
$username
'"
;
$result
=
ExecuteQuery
(
$query
);
return
mysqli_num_rows
(
$result
);
}
function
AddAkun
(
$nama
,
$username
,
$pass
,
$email
,
$role
){
global
$db
;
$query
=
"INSERT INTO akun(nama,username,password,email,role)
VALUES (?,?,?,?,?)"
;
$result
=
$db
->
prepare
(
$query
);
$result
->
bind_param
(
'ssssd'
,
$nama
,
$username
,
$pass
,
$email
,
$role
);
$result
->
execute
();
$result
->
close
();
return
mysqli_affected_rows
(
$db
);
}
function
getAllPaket
(){
$query
=
"SELECT * FROM paket"
;
$result
=
ExecuteQuery
(
$query
);
$data
=
[];
while
(
$paket
=
mysqli_fetch_assoc
(
$result
))
{
$data
[]
=
$paket
;
}
return
$data
;
}
function
CreatePaket
(
$nama
,
$deskripsi
,
$tanggal
,
$gambar
,
$harga
,
$kuota
){
global
$db
;
$query
=
"INSERT INTO paket(nama_paket,deskripsi,tanggal,gambar,harga,kuota) VALUES(?,?,?,?,?,?)"
;
$result
=
$db
->
prepare
(
$query
);
$result
->
bind_param
(
'ssssii'
,
$nama
,
$deskripsi
,
$tanggal
,
$gambar
,
$harga
,
$kuota
);
$result
->
execute
();
$result
->
close
();
return
mysqli_affected_rows
(
$db
);
}
function
DeletePaket
(
$id_paket
){
$query
=
"DELETE FROM paket WHERE id_paket=
$id_paket
"
;
$result
=
ExecuteQuery
(
$query
);
return
$result
;
}
function
EditPaket
(
$id
,
$nama
,
$deskripsi
,
$tanggal
,
$gambar
,
$harga
,
$kuota
){
global
$db
;
$query
=
"UPDATE paket SET nama_paket='
$nama
',deskripsi='
$deskripsi
',
tanggal='
$tanggal
',gambar='
$gambar
',harga='
$harga
',kuota= '
$kuota
'
WHERE id_paket='
$id
'"
;
mysqli_query
(
$db
,
$query
);
return
mysqli_affected_rows
(
$db
);
}
function
getPaket
(){
$query
=
"SELECT * FROM paket"
;
$result
=
ExecuteQuery
(
$query
);
return
$result
;
}
function
getOnePaket
(
$id
){
$query
=
"SELECT * FROM paket WHERE id_paket ='
$id
'"
;
$result
=
ExecuteQuery
(
$query
);
return
$result
;
}
function
getSatuPaket
(
$id
){
$query
=
"SELECT * FROM paket WHERE id_paket = '
$id
'"
;
$result
=
ExecuteQuery
(
$query
);
$data
=
mysqli_fetch_assoc
(
$result
);
return
$data
;
}
function
getEmail
(
$id
){
$query
=
"SELECT email from akun where id_akun = '
$id
'"
;
$result
=
ExecuteQuery
(
$query
);
$data
=
mysqli_fetch_assoc
(
$result
);
return
$data
[
'email'
];
}
function
GetKuota
(
$id_paket
){
$query
=
"SELECT kuota FROM paket WHERE id_paket='
$id_paket
'"
;
$result
=
ExecuteQuery
(
$query
);
$data
=
mysqli_fetch_assoc
(
$result
);
return
$data
[
'kuota'
];
}
function
jumlahTiketTerpakai
(
$id_paket
){
$query
=
"SELECT COUNT(*) AS jlh_tiket FROM tiket WHERE kode_paket='
$id_paket
'"
;
$result
=
ExecuteQuery
(
$query
);
$data
=
mysqli_fetch_assoc
(
$result
);
return
$data
[
'jlh_tiket'
];
}
function
cekTiket
(
$id_paket
,
$id_akun
){
global
$db
;
$query
=
"SELECT COUNT(id_akun) AS id_akun FROM tiket WHERE id_akun='
$id_akun
' AND kode_paket='
$id_paket
'"
;
$result
=
ExecuteQuery
(
$query
);
$data
=
mysqli_fetch_assoc
(
$result
);
return
$data
[
'id_akun'
];
}
function
CreateTiket
(
$id_paket
,
$id_akun
){
global
$db
;
$no_kursi
=
count_kursi
(
$id_paket
);
$total_kursi
=
mysqli_fetch_assoc
(
$no_kursi
);
$total_kursi
=
$total_kursi
[
'total_kursi'
]
+
1
;
$query
=
"INSERT INTO tiket VALUES('','
$id_akun
','
$id_paket
','
$total_kursi
')"
;
$result
=
ExecuteQuery
(
$query
);
return
mysqli_affected_rows
(
$db
);
}
function
count_kursi
(
$id_paket
){
$query
=
"SELECT COUNT(kode_paket) AS total_kursi FROM tiket WHERE kode_paket ='
$id_paket
'"
;
$result
=
ExecuteQuery
(
$query
);
return
$result
;
}
function
GetAllTiketUser
(
$id_akun
){
$query
=
"SELECT * FROM paket INNER JOIN tiket ON paket.id_paket
= tiket.kode_paket WHERE id_akun = '
$id_akun
'"
;
$result
=
ExecuteQuery
(
$query
);
$AllTiket
=
[];
while
(
$data
=
mysqli_fetch_assoc
(
$result
))
{
$AllTiket
[]
=
$data
;
}
return
$AllTiket
;
}
function
caripaket
(
$keyword
){
$query
=
"SELECT * FROM paket WHERE nama_paket LIKE '%
$keyword
%'"
;
return
query
(
$query
);
}
function
DeleteTiket
(
$id_tiket
){
$query
=
"DELETE FROM tiket WHERE id_tiket = '
$id_tiket
'"
;
$result
=
ExecuteQuery
(
$query
);
return
$result
;
}
?>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment