(PECL CUBRID >= 8.3.1)
cubrid_fetch_field — 从结果中获取列信息并作为对象返回
此函数返回一个包含特定列某些属性的对象。对象的属性包括:
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
resultresult 来自于对 cubrid_execute() 的调用
field_offset数值字段偏移量。如果未指定字段偏移量,则检索下一个(尚未通过此函数检索)字段。field_offset 从0开始。
示例 #1 cubrid_fetch_field() 例子
<?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--- 字段属性 ---\n");
printf("%-30s %s\n", "name:", $field->name);
printf("%-30s %s\n", "table:", $field->table);
printf("%-30s \"%s\"\n", "默认值:", $field->def);
printf("%-30s %d\n", "最大长度:", $field->max_length);
printf("%-30s %d\n", "非空:", $field->not_null);
printf("%-30s %d\n", "主键:", $field->primary_key);
printf("%-30s %d\n", "唯一键:", $field->unique_key);
printf("%-30s %d\n", "多键:", $field->multiple_key);
printf("%-30s %d\n", "数值型:", $field->numeric);
printf("%-30s %d\n", "blob:", $field->blob);
printf("%-30s %s\n", "type:", $field->type);
printf("%-30s %d\n", "无符号:", $field->unsigned);
printf("%-30s %d\n", "零填充:", $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