PHP mysqli_fetch_field_direct() 函数

PHP 教程 · 2019-01-27 20:56:30

返回结果集中某个单一字段(列)的 meta-data,并输出字段名称、表格和最大长度:

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

$sql="SELECT name,url FROM websites ORDER BY alexa";


if ($result=mysqli_query($con,$sql))
{
// 获取字段 "name" 的信息
$fieldinfo=mysqli_fetch_field_direct($result,1);

printf("字段名: %s",$fieldinfo->name);
echo "<br>";
printf("数据表: %s",$fieldinfo->table);
echo "<br>";
printf("最大长度: %d",$fieldinfo->max_length);

// 释放结果集
mysqli_free_result($result);
}

mysqli_close($con);
?>

定义和用法

mysqli_fetch_field_direct() 函数从结果集中取得某个单一字段(列)的 meta-data,并作为对象返回。

语法

mysqli_fetch_field_direct(result,fieldnr);

参数 描述
result 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。
fieldnr 必需。规定字段号。必须介于 0 和 字段数-1 之间。

技术细节

返回值: 返回包含字段定义信息的对象。如果没有可用信息则返回 FALSE。该对象有下列属性:
  • name - 列名
  • orgname - 原始的列名(如果指定了别名)
  • table - 表名
  • orgtable - 原始的表名(如果指定了别名)
  • def - 该字段的默认值
  • max_length - 字段的最大宽度
  • length - 在表定义中规定的字段宽度
  • charsetnr - 字段的字符集号
  • flags - 字段的位标志
  • type - 用于字段的数据类型
  • decimals - 整数字段,小数点后的位数
PHP 版本: 5+

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

We Are the Nerds

We Are the Nerds

Christine Lagorio-Chafkin / Hachette Books / 2018-10-2 / USD 18.30

Reddit hails itself as "the front page of the Internet." It's the third most-visited website in the United States--and yet, millions of Americans have no idea what it is. We Are the Nerds is an eng......一起来看看 《We Are the Nerds》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试