From 3cc437bdf8599eb1c3de20745cbe0eab2b957cf5 Mon Sep 17 00:00:00 2001 From: powji17 Date: Fri, 12 Jun 2026 06:23:23 +0700 Subject: [PATCH] memperbaiki koneksi database pada project 1 dan project 2 --- Pertemuan01/hapus_spbu.php | 14 ++------------ Pertemuan01/load_spbu.php | 14 ++------------ Pertemuan01/simpan_spbu.php | 14 ++------------ Pertemuan01/update_spbu.php | 13 ++----------- Pertemuan02/hapus_area.php | 3 ++- Pertemuan02/hapus_jalan.php | 13 ++----------- Pertemuan02/hapus_spbu.php | 13 ++----------- Pertemuan02/load_area.php | 3 ++- Pertemuan02/load_jalan.php | 3 ++- Pertemuan02/load_spbu.php | 13 ++----------- Pertemuan02/simpan_area.php | 3 ++- Pertemuan02/simpan_jalan.php | 3 ++- Pertemuan02/simpan_spbu.php | 14 ++------------ Pertemuan02/update_area.php | 8 ++------ Pertemuan02/update_jalan.php | 8 ++------ Pertemuan02/update_spbu.php | 13 ++----------- 16 files changed, 32 insertions(+), 120 deletions(-) diff --git a/Pertemuan01/hapus_spbu.php b/Pertemuan01/hapus_spbu.php index ec8d657..f254ad2 100644 --- a/Pertemuan01/hapus_spbu.php +++ b/Pertemuan01/hapus_spbu.php @@ -1,18 +1,8 @@ connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); diff --git a/Pertemuan01/load_spbu.php b/Pertemuan01/load_spbu.php index ed542b0..e63b408 100644 --- a/Pertemuan01/load_spbu.php +++ b/Pertemuan01/load_spbu.php @@ -1,18 +1,8 @@ connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); // Ambil semua data dari tabel spbu_point $sql = "SELECT * FROM spbu_point"; diff --git a/Pertemuan01/simpan_spbu.php b/Pertemuan01/simpan_spbu.php index ec59c32..b4c9ee9 100644 --- a/Pertemuan01/simpan_spbu.php +++ b/Pertemuan01/simpan_spbu.php @@ -4,18 +4,8 @@ header('Content-Type: application/json'); // Konfigurasi Database (Sesuaikan dengan milik Anda) -$host = "localhost"; -$user = "root"; -$pass = ""; -$db = "webgis"; // UBAH INI! - -// Koneksi ke database -$conn = new mysqli($host, $user, $pass, $db); - -if ($conn->connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); // Ambil data JSON yang dikirim oleh Fetch API $data = json_decode(file_get_contents("php://input"), true); diff --git a/Pertemuan01/update_spbu.php b/Pertemuan01/update_spbu.php index 1465990..e17d19e 100644 --- a/Pertemuan01/update_spbu.php +++ b/Pertemuan01/update_spbu.php @@ -2,17 +2,8 @@ header('Content-Type: application/json'); // Konfigurasi Database (Sesuaikan dengan milik Anda) -$host = "localhost"; -$user = "root"; -$pass = ""; -$db = "webgis"; // UBAH INI - -$conn = new mysqli($host, $user, $pass, $db); - -if ($conn->connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); diff --git a/Pertemuan02/hapus_area.php b/Pertemuan02/hapus_area.php index 819df19..8f5e260 100644 --- a/Pertemuan02/hapus_area.php +++ b/Pertemuan02/hapus_area.php @@ -1,6 +1,7 @@ connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); diff --git a/Pertemuan02/hapus_spbu.php b/Pertemuan02/hapus_spbu.php index ec8d657..cc1ea4f 100644 --- a/Pertemuan02/hapus_spbu.php +++ b/Pertemuan02/hapus_spbu.php @@ -2,17 +2,8 @@ header('Content-Type: application/json'); // Konfigurasi Database (Sesuaikan) -$host = "localhost"; -$user = "root"; -$pass = ""; -$db = "webgis"; // UBAH INI - -$conn = new mysqli($host, $user, $pass, $db); - -if ($conn->connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); diff --git a/Pertemuan02/load_area.php b/Pertemuan02/load_area.php index f583e4b..e134783 100644 --- a/Pertemuan02/load_area.php +++ b/Pertemuan02/load_area.php @@ -1,6 +1,7 @@ query($sql); diff --git a/Pertemuan02/load_jalan.php b/Pertemuan02/load_jalan.php index 7455a87..0eeca93 100644 --- a/Pertemuan02/load_jalan.php +++ b/Pertemuan02/load_jalan.php @@ -1,6 +1,7 @@ query($sql); diff --git a/Pertemuan02/load_spbu.php b/Pertemuan02/load_spbu.php index ed542b0..93e4302 100644 --- a/Pertemuan02/load_spbu.php +++ b/Pertemuan02/load_spbu.php @@ -2,17 +2,8 @@ header('Content-Type: application/json'); // Konfigurasi Database (Sesuaikan dengan milik Anda) -$host = "localhost"; -$user = "root"; -$pass = ""; -$db = "webgis"; // UBAH INI - -$conn = new mysqli($host, $user, $pass, $db); - -if ($conn->connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); // Ambil semua data dari tabel spbu_point $sql = "SELECT * FROM spbu_point"; diff --git a/Pertemuan02/simpan_area.php b/Pertemuan02/simpan_area.php index 566b5b0..56674ef 100644 --- a/Pertemuan02/simpan_area.php +++ b/Pertemuan02/simpan_area.php @@ -1,6 +1,7 @@ connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); // Ambil data JSON yang dikirim oleh Fetch API $data = json_decode(file_get_contents("php://input"), true); diff --git a/Pertemuan02/update_area.php b/Pertemuan02/update_area.php index cf93d84..43dcda3 100644 --- a/Pertemuan02/update_area.php +++ b/Pertemuan02/update_area.php @@ -1,12 +1,8 @@ connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); diff --git a/Pertemuan02/update_jalan.php b/Pertemuan02/update_jalan.php index e36d3ff..8d486a9 100644 --- a/Pertemuan02/update_jalan.php +++ b/Pertemuan02/update_jalan.php @@ -1,12 +1,8 @@ connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); diff --git a/Pertemuan02/update_spbu.php b/Pertemuan02/update_spbu.php index 1465990..e17d19e 100644 --- a/Pertemuan02/update_spbu.php +++ b/Pertemuan02/update_spbu.php @@ -2,17 +2,8 @@ header('Content-Type: application/json'); // Konfigurasi Database (Sesuaikan dengan milik Anda) -$host = "localhost"; -$user = "root"; -$pass = ""; -$db = "webgis"; // UBAH INI - -$conn = new mysqli($host, $user, $pass, $db); - -if ($conn->connect_error) { - echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); - exit; -} +require_once '../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true);