php mysqli_field_seek()函数

时间:2017-03-02
php mysqli_field_seek()函数将列光标设置为给定的列偏移量。本文章向大家介绍mysqli_field_seek() 函数的基本语法和使用实例,需要的朋友可以参考一下。

定义

mysqli_field_seek()函数将列光标设置为给定的列偏移量。

语法

mysqli_field_seek(result,fieldNumber);

参数

参数 是否必须 描述
result 需要。 由mysqli_query(),mysqli_store_result()或mysqli_use_result()返回的结果集标识符
fieldNumber 需要。 列号。必须是介于0和number_of_columns -1之间的整数

返回值

成功返回TRUE,失败返回FALSE。

实例

以下代码将字段游标设置为结果集中的第一列,然后使用mysqli_fetch_field()获取列信息,并打印字段的名称,表和最大长度。

<?php
//  http://www.manongjc.com/article/1666.html
//  作者:码农教程
$con=mysqli_connect("localhost","my_user","my_password","my_db");

if (mysqli_connect_errno($con)){
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="SELECT name FROM emp";

if ($result=mysqli_query($con,$sql)){
  // Get field info for 1st column ("Lastname")
  mysqli_field_seek($result,0);
  $fieldinfo=mysqli_fetch_field($result);

  print $fieldinfo->name;
  print $fieldinfo->table;
  print $fieldinfo->max_length;

  // Free result set
  mysqli_free_result($result);
}

mysqli_close($con);
?>