<?Php
require "config.php";// Database connection file.
$query="select * from student LIMIT 0,5 ";
if ($result_set = $connection->query($query)) {
while($row = $result_set->fetch_array(MYSQLI_ASSOC)){
echo $row['id'],$row['name'],$row['class'],$row['mark']."<br>";
}
$result_set->close();
}
?>
Syntax
$result_set=mysqli_query($connection,$query,MYSQLI_STORE_RESULT);
$result_set=$connection->($query,MYSQLI_STORE_RESULT)
$result_set is FALSE on failure , for SELECT ,SHOW or EXPLAIN we will get mysqli_result object. For other ( successful ) queries we get TRUE as return value.
MySQLI database connection file
By using fetch_array() we get an array of column data as elements. We will get NULL value if there is no more rows in resultset. ( So our while loop will end after going through all rows of returned result set )<?Php
require "config.php";// Database connection file.
$query="select * from student ";
if ($result_set = $connection->query($query)) {
echo "Total No. of records :".$result_set->num_rows;
$result_set->close();
}
?>
Procedural style
<?Php
require "config.php";// Database connection file.
$query="select * from student LIMIT 0,5 ";
if ($result_set = mysqli_query($connection,$query)) {
while($row = $result_set->fetch_array(MYSQLI_ASSOC)){
echo $row['id'],$row['name'],$row['class'],$row['mark']."<br>";
}
$result_set->close();
}?>
$t="SELECT * FROM istudent where mark >90";
$check=$connection->query($t);
if(mysqli_num_rows($check)>0){
// record found
}else{
// No record found
}
$query="UPDATE student SET class='Five'";
if ($connection->query($query)) {
echo "Records Updated";
}else{
echo $connection->error;
}

Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.