Connect PHP with MySQL and display data rows into HTML table

MySQL Database having table name “emp” has records as below,


Below is the source code to connect PHP with MySQL:

<!DOCTYPE html>
mysql_connect(“localhost”, “root”, “”) or die(mysql_error());
mysql_select_db(“Employeedb”) or die(mysql_error());
$data = mysql_query(“Select * from emp”)
or die(mysql_error());

while($row = mysql_fetch_assoc($data))

echo “<table style=’border: 1px solid black; width:40%’>
<td style=’border: 1px solid black; width:20%’>”.$row[“EmpID”]
<td style=’border: 1px solid black;’>”.$row[“EmpName”]


Below is output: