To raise knowledge, to rise Knowledge: thinkphp framework where conditions query MySQL database If a field is empty

Source: Internet
Author: User

Code abuse me times, I to code such as first love ~

Problem:

Querying a field app_date whether the data is null, the normal way we do this is:

$map Array (' eq ', ' null '); $data M ("Info") , Field ("*"), where ($map), select ()

Use echo M ("Info")->getlastsql (); Print SQL statements as follows:

SELECT ' id ', ' name ', ' create_time ', ' app_data ' from ' info ' WHERE ' app_data ' = ' NULL '

But the printed SQL statement is not what I want to do, hair, modify the test, modify the test, always do not reach the correct SQL statement I want, the following is correct:

SELECT ' id ', ' name ', ' create_time ', ' app_data ' from ' info ' WHERE ' app_data ' is NULL

The solution is always there, how to do, look at the document, go through the document in At the bottom you see something like this :

Correct judgment Method:

$map Array (' EXP ', ' is NULL ');; $data = M ("Info"), Field ("*"), where ($map), select ()

To print the SQL statement:

SELECT ' id ', ' name ', ' create_time ', ' app_data ' from ' info ' WHERE ' app_data ' is NULL

Perfect ~~~~~~~

To raise knowledge, to rise Knowledge: thinkphp framework where conditions query MySQL database If a field is empty

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.