PHP8 cubrid_fetch_field

2024-03-29 09:17 更新

(PECL CUBRID >= 8.3.1)

cubrid_fetch_field — 从结果中获取列信息并作为对象返回

说明

cubrid_fetch_field(resource $result, int $field_offset = 0): object

此函数返回一个对象,该对象具有特定 列。该对象的属性包括:

name

列名称

table

列所属的表的名称

def

列的默认值

max_length

列的最大长度

not_null

如果列不能为 NULL,则为 1

primary_key

如果列是主键,则为 1

unique_key

如果列是唯一键,则为 1

multiple_key

如果列是非唯一键,则为 1

numeric

如果列为数值,则为 1

blob

如果列是 BLOB,则为 1

type

列的类型

unsigned

如果列是无符号的,则为 1

zerofill

如果列为零填充,则为 1

参数 

result

result来自对 cubrid_execute() 的调用

field_offset

数值字段偏移量。如果未指定字段偏移量,则 检索下一个字段(此函数尚未检索到该字段)。 从 0 开始。field_offset

返回值 

当进程成功时,具有特定列的某些属性的对象。

失败时为 false。

示例 

示例 #1 cubrid_fetch_field() example

<?php
$conn = cubrid_connect("localhost", 33000, "demodb");
$req = cubrid_execute($conn, "SELECT event_code,athlete_code,nation_code,game_date FROM game WHERE host_year=1988 and event_code=20001;");

var_dump(cubrid_fetch_row($req));

cubrid_field_seek($req, 1);
$field = cubrid_fetch_field($req);

printf("\n--- Field Properties ---\n");
printf("%-30s %s\n", "name:", $field->name);
printf("%-30s %s\n", "table:", $field->table);
printf("%-30s \"%s\"\n", "default value:", $field->def);
printf("%-30s %d\n", "max length:", $field->max_length);
printf("%-30s %d\n", "not null:", $field->not_null);
printf("%-30s %d\n", "primary key:", $field->primary_key);
printf("%-30s %d\n", "unique key:", $field->unique_key);
printf("%-30s %d\n", "multiple key:", $field->multiple_key);
printf("%-30s %d\n", "numeric:", $field->numeric);
printf("%-30s %d\n", "blob:", $field->blob);
printf("%-30s %s\n", "type:", $field->type);
printf("%-30s %d\n", "unsigned:", $field->unsigned);
printf("%-30s %d\n", "zerofill:", $field->zerofill);

cubrid_close_request($req);

cubrid_disconnect($conn);
?>

以上示例会输出:

array(4) {
  [0]=>
  string(5) "20001"
  [1]=>
  string(5) "16681"
  [2]=>
  string(3) "KOR"
  [3]=>
  string(9) "1988-9-30"
}

--- Field Properties ---
name:                          athlete_code
table:                         game
default value:                 ""
max length:                    0
not null:                      1
primary key:                   1
unique key:                    1
multiple key:                  0
numeric:                       1
blob:                          0
type:                          integer
unsigned:                      0
zerofill:                      0


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号