From 264a9df2896c51eeb184396e5dd6c2cb68767d00 Mon Sep 17 00:00:00 2001 From: fauzannaufan <fauzannaufan@gmail.com> Date: Thu, 31 Mar 2016 15:18:51 +0700 Subject: [PATCH] DB Function --- LGM/db.php | 21 +++++++++++++++++++++ LGM/index.php | 13 +++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 LGM/db.php diff --git a/LGM/db.php b/LGM/db.php new file mode 100644 index 0000000..009b461 --- /dev/null +++ b/LGM/db.php @@ -0,0 +1,21 @@ +<?php + + function connect() { + $conn = new mysqli("localhost", "root", "", "LGM"); + if ($conn->connect_error) { + die($conn->connect_error); + } + echo "Connected<br>"; + return $conn; + } + + function close($conn) { + $conn->close(); + echo "Closed<br>"; + } + + function query($conn, $sql) { + return $conn->query($sql); + } + +?> \ No newline at end of file diff --git a/LGM/index.php b/LGM/index.php index e69de29..da3199f 100644 --- a/LGM/index.php +++ b/LGM/index.php @@ -0,0 +1,13 @@ +<?php + + include 'db.php'; + + $conn = connect(); + $data = query($conn, "SELECT * FROM coba"); + while ($row = $data->fetch_assoc()) { + echo "Id : ".$row["id"]." - Teks: ".$row["teks"]."<br>"; + } + query($conn, "DELETE FROM coba WHERE id=2"); + close($conn); + +?> \ No newline at end of file -- GitLab