metadata php,Metadata - [ php中文手册 ] - 在线原生手册 - php中文网

Metadata

A MySQL result set contains metadata. The metadata describes the columns

found in the result set. All metadata sent by MySQL is accessible

through the mysqli interface.

The extension performs no or negligible changes to the

information it receives.

Differences between MySQL server versions are not aligned.

Meta data is access through the mysqli_result interface.

Example #1 Accessing result set meta data

$mysqli = new mysqli ( "example.com" , "user" , "password" , "database" );

if ( $mysqli -> connect_errno ) {

echo "Failed to connect to MySQL: (" . $mysqli -> connect_errno . ") " . $mysqli -> connect_error ;

} $res = $mysqli -> query ( "SELECT 1 AS _one, 'Hello' AS _two FROM DUAL" ); var_dump ( $res -> fetch_fields ()); ?>

以上例程会输出:

array(2) {

[0]=>

object(stdClass)#3 (13) {

["name"]=>

string(4) "_one"

["orgname"]=>

string(0) ""

["table"]=>

string(0) ""

["orgtable"]=>

string(0) ""

["def"]=>

string(0) ""

["db"]=>

string(0) ""

["catalog"]=>

string(3) "def"

["max_length"]=>

int(1)

["length"]=>

int(1)

["charsetnr"]=>

int(63)

["flags"]=>

int(32897)

["type"]=>

int(8)

["decimals"]=>

int(0)

}

[1]=>

object(stdClass)#4 (13) {

["name"]=>

string(4) "_two"

["orgname"]=>

string(0) ""

["table"]=>

string(0) ""

["orgtable"]=>

string(0) ""

["def"]=>

string(0) ""

["db"]=>

string(0) ""

["catalog"]=>

string(3) "def"

["max_length"]=>

int(5)

["length"]=>

int(5)

["charsetnr"]=>

int(8)

["flags"]=>

int(1)

["type"]=>

int(253)

["decimals"]=>

int(31)

}

}

Prepared statements

Meta data of result sets created using prepared statements are accessed

the same way. A suitable mysqli_result handle is

returned by mysqli_stmt_result_metadata().

Example #2 Prepared statements metadata

$stmt = $mysqli -> prepare ( "SELECT 1 AS _one, 'Hello' AS _two FROM DUAL" ); $stmt -> execute (); $res = $stmt -> result_metadata (); var_dump ( $res -> fetch_fields ()); ?>

See also

mysqli::query()

mysqli_result::fetch_fields()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值