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:
- $sql = "select * form abc"
- $result = MySQL_query($sql);
- $row = MySQL_fetch_array($result);
If (empty ($ row) // start to judge whether it is null
- {
- echo "null";
- }
- else
- {
- echo "not null";
- }
Php uses the empty function to determine whether MySQL forms are empty. Method 2:
- $sql = "select * form abc"
- $result = MySQL_query($sql);
- $row = MySQL_fetch_array($result);
If (! $ Row) // It is null enough to start judgment.
- {
- echo "null";
- }
- else
- {
- 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
- $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.