PHP mysqli_field_count()Functions

PHP MySQLi 参考手册PHP MySQLi Reference Manual

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

<?php 
// 假定数据库用户名:root,密码:123456,数据库:EXAMPLE 
$con=mysqli_connect("localhost","root","123456","EXAMPLE"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "连接 MySQL 失败: " . mysqli_connect_error(); 
} 

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

// 获取列数
echo mysqli_field_count($con);


mysqli_close($con);
?>

Definition and Usage

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


Syntax

mysqli_field_count(connection);

Parameters 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+


PHP MySQLi 参考手册PHP MySQLi Reference Manual Other Extensions