PHP Code to connect and list record

<?php
//database connect
$db=mysqli_connect("localhost","root","","mycompanyhr");

//checking database connection
if ($db==false) {
echo "Connect failed: ";
echo mysqli_connect_error($db);
exit();
}
else {
echo "Connection successful";
}

$sql="select EMPNO, FIRSTNAME, LASTNAME, WORKDEPT,
PHONENO from employee";

$rs=mysqli_query($db, $sql);
if($rs==false){
echo ("Query cannot be executed!<br>");
echo ("SQL Error : ".mysqli_error($db));
}
else {
while($rekod=mysqli_fetch_array($rs)){
echo $rekod['EMPNO']."<br>";
echo $rekod['FIRSTNAME']."<br>";
echo $rekod['LASTNAME']."<br>";
echo $rekod['WORKDEPT']."<br>";
echo $rekod['PHONENO']."<hr>";
}
}
?>

Popular Posts

WorldConferences.net