Home  >  Article  >  Backend Development  >  How does php determine whether the mysql query result is empty?

How does php determine whether the mysql query result is empty?

藏色散人
藏色散人Original
2021-07-23 09:15:074509browse

php method to determine whether the mysql query result is empty: 1. Query through the "if (mysql_num_rows($rows) < 1){...}" method; 2. Query through "if(!mysql_affected_rows( )){...}" method query.

How does php determine whether the mysql query result is empty?

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php determine whether the mysql query result is null?

php determines whether the query result of the SQL statement is empty

determines whether the result set of the SQL statement query is empty!

<?php
//方法一 获取select结果集的行数
$rows=mysql_query("select * from `student` where `age`=&#39;16&#39;;");
if (mysql_num_rows($rows) < 1){
echo &#39;查询无数据!&#39;;
}
//方法二 返回上一次操作受影响的行数
$rows=mysql_query("select * from `student` where `age`=&#39;16&#39;;");
if(!mysql_affected_rows()){
    echo &#39;查询无数据!&#39;;
}
?>

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How does php determine whether the mysql query result is empty?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn