mysqli::$field_count
mysqli::$field_count
mysqli_field_count
(PHP 5, PHP 7)
mysqli :: $ field_count - mysqli_field_count - 返回最近查询的列数
Description
面向对象的风格
int $mysqli->field_count;
程序风格
int mysqli_field_count ( mysqli $link )
返回link
参数表示的连接上最近一次查询的列数。在使用mysqli_store_result()函数确定查询是否应该产生非空结果集而不知道查询的性质时,此函数可能很有用。
Parameters
`link`
仅过程样式:由mysqli_connect()或mysqli_init()返回的链接标识符
Return Values
表示结果集中字段数的整数。
Examples
Example #1 $mysqli->field_count example
面向对象的风格
<?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')"
$mysqli->real_query("SELECT * FROM friends"
if ($mysqli->field_count) {
/* this was a select/show or describe query */
$result = $mysqli->store_result(
/* process resultset */
$row = $result->fetch_row(
/* free resultset */
$result->close(
}
/* close connection */
$mysqli->close(
?>
程序风格
<?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')"
mysqli_real_query($link, "SELECT * FROM friends"
if (mysqli_field_count($link)) {
/* this was a select/show or describe query */
$result = mysqli_store_result($link
/* process resultset */
$row = mysqli_fetch_row($result
/* free resultset */
mysqli_free_result($result
}
/* close connection */
mysqli_close($link
?>
← mysqli::$error
mysqli::get_charset →
© 1997–2017 The PHP Documentation Group
根据知识共享署名许可证v3.0或更高版本授权。