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