Checks whether MySQL forms are empty and empty functions are available.

Source: Internet
Author: User

The following article mainly introduces php's use of the empty function to determine whether MySQL forms are empty. We all know that php does not have a direct function to determine whether database fields are empty, however, we can use the return function of MySQL_fetch_array.

Value.

For example.

Php uses the empty function to determine whether MySQL forms are empty. Method 1:

 
 
  1. $sql = "select * form abc" 
  2. $result = MySQL_query($sql);  
  3. $row = MySQL_fetch_array($result); 

If (empty ($ row) // start to judge whether it is null

 
 
  1. {  
  2. echo "null";  
  3. }  
  4. else  
  5. {  
  6. echo "not null";  

Php uses the empty function to determine whether MySQL forms are empty. Method 2:

 
 
  1. $sql = "select * form abc" 
  2. $result = MySQL_query($sql);  
  3. $row = MySQL_fetch_array($result); 

If (! $ Row) // It is null enough to start judgment.

 
 
  1. {  
  2. echo "null";  
  3. }  
  4. else  
  5. {  
  6. echo "not null";  

In fact, when the MySQL_fetch_array function is used, if the table is an empty table, false is returned. At this time, $ row is not successfully assigned a value. Remember, never dare to use it like this

 
 
  1. $row =  mysql _fetch_array($result)or die(mysql_error()); 

If the program is followed by yo or die, the execution of mysql_fetch_array will be terminated. The above content is an introduction to php's use of the empty function to determine whether the MySQL form is empty.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.