我们通过对
mysql_num_fields()函数可以将要查询的表内所有字段的数目统计出来,该函数的语法格式如下:
int mysql_num_fields ( resource $result )
其中参数result是mysql_query()函数执行后返回的结果集。使用mysql_num_fields()函数的PHP获取字段数目示例代码如下:
- ?php
-
$connection=mysql_connect("localhost",
"root","root") or die("连接服务器失败");
- mysql_select_db("sunyang",$connection)
or die("选择数据库失败"); -
$query="select * from employee";
-
$result=mysql_query($query) or
die("查询数据失败"); //执行查询
- echo mysql_num_fields($result);
//输出字段的数目 - mysql_free_result($result);
- mysql_close();
-
?>
以上就是PHP获取字段数目的相关实现方法介绍。
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn