Skip to content

Instantly share code, notes, and snippets.

@dikiwidia
Created May 24, 2020 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dikiwidia/d685b0401d0de8299bd8858f773fa7cc to your computer and use it in GitHub Desktop.
Save dikiwidia/d685b0401d0de8299bd8858f773fa7cc to your computer and use it in GitHub Desktop.
Koneksi ke Database
<?php
$ip = "localhost";
$username = "pma"; // default xampp "root"
$password = "admin123"; // default xampp ""
$database = "belajar";
$conn = new mysqli($ip,$username,$password,$database);
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: " . $conn->connect_error;
exit();
}
?>
<?php
include "koneksi.php";
// Buat Query
$sql = "SELECT * FROM user";
$query = $conn->query($sql);
// Looping Data
while($row = $query->fetch_array()){
echo $row['nama']." (".$row['alamat'].") - JK:".$row['jenis_kelamin'];
echo "<br />";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment