35 Program to display data from MySQL Database in PHP.

Program:

<?php
 
    $host = "localhost";
 
    $user = "root";
 
    $pass = "1234";
 
    $dbname = "employees";
 
 
 
    $conn = mysqli_connect($host,$user,$pass,$dbname);
 
 
 
    if(!$conn)
 
    {
 
        die('Could Not Connect:'.mysqli_errort());
 
    }
 
        
 
    echo "Connected Successfully:
";
 
    $sql = "Select * from emp";
 
 
 
    $retval = mysqli_query($conn,$sql);
 
 
 
 
 
    if(mysqli_num_rows($retval)>0)
 
    {
 
        while($row = mysqli_fetch_assoc($retval))
 
        {
 
            echo "-------------
";
 
            echo "EmpID: {$row['id']}
";
 
            echo "Name: {$row['name']}
";
 
            echo "Salary: {$row['Salary']}
";
 
            echo "-------------
";
 
        }
 
    }
 
    else
 
    {
 
        echo "0 results";
 
    }
 
    
 
    mysqli_close($conn);   
 
?>


Output:

Program to display data from MySQL Database in PHP.