Program:
Output:
<?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: