The common and basic module where we require in php programming is to retrieve data from database and show in html page. Lets follow the basics steps for demostration
create a folder inside htdocs folder, with a name you like and create two files with the name of index.php and connection.php. connection file content would be as follows
$conn=mysqli_connect(“localhost“,“root“,““,“mydb“);
if (mysqli_connect_errno()) {
echo “Failed to connect to MySQL: “ . mysqli_connect_error();
}
connection format:mysqli_connect("HOST","USER","PASSWORD","DATABASE");
lets write following content inside index.php file
<table>
<thead>
<td>USER ID</td>
<td>NAME</td>
<td>AGE</td>
</thead>
<tbody>
<?php
include('connection.php');
$result=mysqli_query($conn,"SELECT * FROM mytable");
while($user=mysqli_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $user['userId']; ?></td>
<td><?php echo $user['name']; ?></td>
<td><?php echo $user['age']; ?></td>
</tr>
<?php
}
?>
</tbody>
<table>
you will see the following output from the browser if you visit localhost/phptest/