Pull out thinkphp database operation class

Source: Internet
Author: User

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

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.