Last active
October 6, 2021 16:00
-
-
Save RobyCigar/26f3e29e6ec26f604cdf1338fbe03736 to your computer and use it in GitHub Desktop.
Catatan PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Masuk ke db | |
mysql -u root -p | |
<?php | |
// Koneksi ke Database | |
$conn = mysqli_connect("localhost", "root", "root", "pw_043040023"); | |
function query($sql) { | |
global $conn; | |
$result = mysqli_query($conn, $sql); | |
$rows = []; | |
while( $row = mysqli_fetch_assoc($result) ) { | |
$rows[] = $row; | |
} | |
return $rows; | |
} | |
function hapus($id) { | |
global $conn; | |
mysqli_query($conn, "delete from mahasiswa where id = $id"); | |
return mysqli_affected_rows($conn); | |
} | |
function tambah($data) { | |
global $conn; | |
$nrp = htmlspecialchars($data["nrp"]); | |
$nama = htmlspecialchars($data["nama"]); | |
$email = htmlspecialchars($data["email"]); | |
$jurusan = htmlspecialchars($data["jurusan"]); | |
$gambar = htmlspecialchars($data["gambar"]); | |
$sql = "INSERT INTO mahasiswa | |
VALUES | |
('', '$nrp', '$nama', '$email', '$jurusan', '$gambar')"; | |
mysqli_query($conn, $sql); | |
return mysqli_affected_rows($conn); | |
} | |
function ubah($data) { | |
global $conn; | |
$id = $data["id"]; | |
$nrp = htmlspecialchars($data["nrp"]); | |
$nama = htmlspecialchars($data["nama"]); | |
$email = htmlspecialchars($data["email"]); | |
$sql = "UPDATE mahasiswa SET | |
nrp = '$nrp', | |
nama = '$nama', | |
email = '$email', | |
WHERE | |
id = $id | |
"; | |
mysqli_query($conn, $sql); | |
return mysqli_affected_rows($conn); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Query database