PHP | mysqli_num_rows()函数

mysqli_num_rows()函数是PHP中的一个内置函数,用于返回结果集中的行数。它通常用于检查数据库中是否存在数据。要使用此功能,必须首先设置与MySQL数据库的连接。

null

语法:

mysqli_num_rows ( $result );

参数: 此函数接受单个参数$result(其中$result是使用mysqli_query()设置的MySQL查询)。它是一个强制参数,表示MySQL中的fetch查询返回的结果集。

返回值: 它返回结果集中存在的行数。如果没有与给定条件匹配的行,则返回false。

考虑有一个名为 笨蛋 在一个名为 极客 .以下是表格极客的描述。

用户名 暗语
天哪 通行证1
极客2 密码2
极客3 Pass3
极客4 Pass4

下面的程序演示了PHP中的mysqli_num_rows()函数。

<?php
// Setting up connection with database Geeks
$connection = mysqli_connect( "localhost" , "root" , "" ,
"Geeks" );
// Check connection
if (mysqli_connect_errno())
{
echo "Database connection failed." ;
}
// query to fetch Username and Password from
// the table geek
$query = "SELECT Username, Password FROM geek" ;
// Execute the query and store the result set
$result = mysqli_query( $connection , $query );
if ( $result )
{
// it return number of rows in the table.
$row = mysqli_num_rows( $result );
if ( $row )
{
printf( "Number of row in the table : " . $row );
}
// close the result.
mysqli_free_result( $result );
}
// Connection close
mysqli_close( $connection );
?>


输出 :

Number of row in the table : 4

PHP是一种专门为web开发设计的服务器端脚本语言。通过以下步骤,您可以从头开始学习PHP PHP的教程 PHP示例 .

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享