<?Php
require "config.php";// Database connection file.
if ($result = $connection->query("SELECT * FROM student")) {
$field_no = $result->field_count;
echo " Total Number of Fields ".$field_no;
$result->close();
}
?>
Total Number of Fields 5
$result_set->field_count;
mysqli_num_fields($result_set)
The input parameter $result_set is the output of result set identifier of mysqli_query(), mysqli_store_result() or mysqli_use_result().
MySQLI database connection file
Example : Object Oriented Style<?Php
require "config.php";// Database connection file.
if ($result = $connection->query("SELECT * FROM student")) {
$field_no = $result->field_count;
echo " Total Number of Fields ".$field_no;
$result->close();
}
?>
Total Number of Fields 5Procedural style
<?Php
require "config.php";// Database connection file.
if ($result_set = mysqli_query($connection,$query)) {
echo "Total No. of fields :".mysqli_num_fields($result_set);
mysqli_free_result($result_set);
}
?>
Total No. of fields :5MYSQLI Functions mysqli_fetch_field_direct() mysqli_num_rows() Number of rows in result set SELECT query UPDATE query
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.