PHP is one of the popular programming languages, in Indonesia, the programming language is often the first language taught in high school or college to study server-side scripting. Generally, PHP programming languages ​​are often used to build a website, but with PHP development itself which has now reached version 7, it allows us to build an API service that can also be used to improve the quality of website and game services that allow players to store their data inside the server.

In this tutorial, I use Linux as my operating system and use PHP version 7.2.5. First, make sure you have installed Apache and MySql and have created a database that we will connect to, here I have created a database named mahasiswa.

Next, open the text editor that we normally use, here I use vs code and type the code below:

<?php
$hostname=”localhost”;
$username=”your database username”;
$password=”your database password”;
$database=”your database name”;
$conn=mysqli_connect($hostname,$username,$password,$database);
$query=”SELECT*FROM mahasiswa”;
$result=mysqli_query($conn,$query);
$rows=[];
while($row=mysqli_fetch_assoc($result))
$rows[]=$row;
return$rows;
?>