Easy Tutorial
❮ Func Array Values Func Mysqli Select Db ❯

PHP mysqli_field_count() Function

PHP MySQLi Reference Manual

Assume we have a "websites" table with 5 fields and 20 rows of records. Return the number of columns in the most recent query:

<?php 
// Assume database username: root, password: 123456, database: tutorialpro 
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

mysqli_query($con, "SELECT * FROM websites");

// Get the number of columns
echo mysqli_field_count($con);

mysqli_close($con);
?>

Definition and Usage

The mysqli_field_count() function returns the number of columns in the most recent query.


Syntax

Parameter Description
connection Required. Specifies the MySQL connection to use.

Technical Details

Return Value: Returns an integer representing the number of columns in the result set.
PHP Version: 5+
--- ---

❮ Func Array Values Func Mysqli Select Db ❯