mysqli_stmt::result_metadata
mysqli_stmt::result_metadata
mysqli_stmt_result_metadata
(PHP 5, PHP 7)
mysqli_stmt :: result_metadata - mysqli_stmt_result_metadata - 从预处理语句返回结果集元数据
描述
面向对象的风格
mysqli_result mysqli_stmt::result_metadata ( void )
程序风格
mysqli_result mysqli_stmt_result_metadata ( mysqli_stmt $stmt )
如果传递给mysqli_prepare()的语句是产生结果集的语句,mysqli_stmt_result_metadata()
返回可用于处理元信息的结果对象,例如字段总数和单个字段信息。
注意
:此结果集指针可以作为参数传递给处理结果集元数据的任何基于字段的函数,例如:
- mysqli_num_fields()
- mysqli_fetch_field()
- mysqli_fetch_field_direct()
- mysqli_fetch_fields()
- mysqli_field_count()
- mysqli_field_seek()
- mysqli_field_tell()
当你完成它的时候,结果集结构应该被释放,你可以通过将它传递给mysqli_free_result()
注意
:mysqli_stmt_result_metadata()
返回的结果集仅包含元数据。它不包含任何行结果。这些行是通过使用带mysqli_stmt_fetch()的语句句柄获取的。
参数
`stmt`
仅过程风格:由mysqli_stmt_init()返回的语句标识符。
返回值
返回结果对象或FALSE
发生错误。
例子
Example #1 Object oriented style
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "test"
$mysqli->query("DROP TABLE IF EXISTS friends"
$mysqli->query("CREATE TABLE friends (id int, name varchar(20))"
$mysqli->query("INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')"
$stmt = $mysqli->prepare("SELECT id, name FROM friends"
$stmt->execute(
/* get resultset for metadata */
$result = $stmt->result_metadata(
/* retrieve field information from metadata result set */
$field = $result->fetch_field(
printf("Fieldname: %s\n", $field->name
/* close resultset */
$result->close(
/* close connection */
$mysqli->close(
?>
Example #2 Procedural style
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "test"
mysqli_query($link, "DROP TABLE IF EXISTS friends"
mysqli_query($link, "CREATE TABLE friends (id int, name varchar(20))"
mysqli_query($link, "INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')"
$stmt = mysqli_prepare($link, "SELECT id, name FROM friends"
mysqli_stmt_execute($stmt
/* get resultset for metadata */
$result = mysqli_stmt_result_metadata($stmt
/* retrieve field information from metadata result set */
$field = mysqli_fetch_field($result
printf("Fieldname: %s\n", $field->name
/* close resultset */
mysqli_free_result($result
/* close connection */
mysqli_close($link
?>