thinkphp database Operation class

Source: Internet
Author: User

Query method:
$db->table (' user ')->limit->order (' id desc ')->select ();
Equivalent to executing the following SQL statement and returning a two-dimensional array.
SELECT * from ' user ' ORDER by id desc LIMIT 10
$where [' user_name '] = array (' Like ', '%ly% ');
$where [' credit '] = Array (' GT ', 100);
$db->table (' user ')->where ($where)->limit ()->select ();
Equivalent to executing the following SQL statement and returning a two-dimensional array.
SELECT * from ' user ' WHERE (' user_name ' like '%ly% ') and (' Credits ' >) LIMIT 10
$where [' credit '] = Array (' GT ', ' + '), array (' EQ ', 0), ' or ');
$db->table (' user ')->where ($where)->limit ()->select ();
Equivalent to executing the following SQL statement and returning a two-dimensional array.
SELECT * from ' user ' WHERE (' credits ' > ') OR (' credit ' = 0) ' LIMIT 10
$where [' _string '] = ' credit>100 and credit<200 ';
$db->table (' user ')->where ($where)->limit ()->select ();
Equivalent to executing the following SQL statement and returning a two-dimensional array.
SELECT * from ' user ' WHERE (credit>100 and credit<200) LIMIT 10
$where [' user_name '] = ' lyly ';
$db->table (' user ')->field (' Credit ')->where ($where)->find ();
Equivalent to executing the following SQL statement and returning a one-dimensional array.
SELECT ' credits ' from ' User ' WHERE (' user_name ' = ' lyly ') LIMIT 0,1
$db->table (' user ')->where (' id=2 ')->find ();
Equivalent to executing the following SQL statement and returning a one-dimensional array.
SELECT * from ' user ' WHERE id=2 LIMIT 0,1
Take a look at the UPDATE statement:
$where [' user_name '] = ' lyly ';
$data [' credit '] = 100;
$db->table (' user ')->data ($data)->where ($where)->update ();
is equivalent to executing the following SQL statement and returning the number of affected rows.
UPDATE ' user ' SET ' credit ' =100 WHERE (' user_name ' = ' lyly ')
$where [' credit '] = Array (' ELT ', 100);
$data [' credit '] = Array (' exp ', ' credit+1 ');
$db->table (' user ')->data ($data)->where ($where)->update ();
is equivalent to executing the following SQL statement and returning the number of affected rows.
UPDATE ' user ' SET ' credit ' =credit+1 WHERE (' credits ' <= 100)
Let's take a look at the new statement:
$data [' user_name '] = ' hoho ';
$data [' credit '] = 100;
$db->table (' user ')->data ($data)->insert ();
Equivalent to executing the following SQL statement and returning the self-increment ID.
INSERT into ' user ' (' user_name ', ' credits ') VALUES (' HoHo ', 100)
Finally, take a look at the DELETE statement:
$where [' credit '] = 0;
$db->table (' user ')->where ($where)->delete ();
is equivalent to executing the following SQL statement and returning the number of affected rows.
DELETE from ' user ' WHERE (' credits ' = 0)

thinkphp database Operation class

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.