PHP mysqli_field_count () function
Suppose we have a "websites" table with five fields 20 rows. Returns the number of columns in recent query:
<?php // 假定数据库用户名:root,密码:123456,数据库:w3big $con=mysqli_connect("localhost","root","123456","w3big"); 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
mysqli_field_count () function returns the number of columns in a recent query.
grammar
mysqli_field_count( connection ) ;
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
technical details
return value: | It returns an integer that represents the number of columns in the result set. |
---|---|
PHP version: | 5+ |
PHP MySQLi Reference Manual