If you are a thinkphp user, you will find it very convenient to operate the database thinkphp. Now there is a very small job in front of you, so small that there is absolutely no need to use thinkphp to finish it. But you think it's very troublesome to operate the database without thinkphp. At this point, you are caught in a dilemma. Well, the following I would like to share this database operation class, may help you get rid of this dilemma. Although this database operation class can not be said to be completely deducted from the thinkphp, but more or less can see thinkphp the shadow of the year, using very similar, is really convenient to use AH.
All right, now, let's show the basic usage.
Let's start by demonstrating the 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 ORDER by desc Ten
$where[' user_name '] =Array' like','%ly%');$where[' Credit '] =Array'GT', -); $db -Table('User') -where($where) -LimitTen) -Select();
Equivalent to executing the following SQL statement and returning a two-dimensional array.
SELECT * from WHERE ('user_namelike'%ly%'and> Ten
$where[' Credit '] =Array (Array ('GT', -), Array ('eq',0),'or'); $db -Table('User') -where($where) -LimitTen) -Select();
Equivalent to executing the following SQL statement and returning a two-dimensional array.
SELECT * from WHERE > - OR = 0 Ten
$db,table('user'),where(' id=2'), find ();
Equivalent to executing the following SQL statement and returning a one-dimensional array.
SELECT * from WHERE id=20,1
Take a look at the UPDATE statement:
$where[' user_name '] = 'lyly'; $data[' Credit '] = -; $db -Table('User') -Data ($DATA) -where($where) -Update();
is equivalent to executing the following SQL statement and returning the number of affected rows.
UPDATE SET ' credit '=WHERE ('user_name='lyly ' )
$where[' Credit '] =Array'ELT', -); $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 SET ' credits '=credit+1WHERE<=
Take a look at the new statement:
$data[' user_name ']='hoho'; $data[ ' credit ']=: $dbtable( ' User ') Insert(), data ($data);
Equivalent to executing the following SQL statement and returning the self-increment ID.
INSERT into ' hoho_user ' ('user_nameVALUES ' ('hoho')
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 WHERE = 0 )
For more detailed usage, interested persons can consult the thinkphp manual or download the code for their own study.
: HTTP://PAN.BAIDU.COM/S/1EQ4LCDK
Pull out thinkphp database operation class