TP5 implementation code Sharing for database Curl operations

Source: Internet
Author: User
TP5 Implementation code sharing for database Curl operations

Db::query ();D b::execute ();D b::table ()->select (), all data, two-dimensional array, the result does not exist when returning an empty array db::table->find (); one data, one-dimensional array, Returns Nulldb::table->value () when the result does not exist, returns an empty Db::table->column () when the result does not exist, returns a one-dimensional array, or, if there is a second argument, returns an array with the second number as the identity, when the result does not exist , return nulldb::table ()-> Table name plus table prefix db::name ()-> Ignore table prefixes


Add Data "Array"

Db::name ()->insert (); Returns the number of rows affected Db::name ()->insertgetid (); Get the last New Iddb::name ()->insertall (); Insert all data

Update Database "Array"

Db::name ()->where ()->update (); Returns the number of rows affected by Db::name ()->where ()->setfield (' name ', ' millet '); A field that updates data returns the number of rows affected Db:name ()->where->setinc (' num '); num field name each time self-increment 1db:name ()->where->setinc (' num ', 5); num field name per Increment 5db::name ()->where ()->setdec (' num '); num field each time self-decrement


Delete

Db::name ()->where ()->delete (); Returns the number of affected rows


If the condition you want to delete is a primary key, you can not write where

Db::name ()->delete (1); Delete a id=1 record


Conditional constructors

Db::name ()->where ()->buildsql (); Returns the SQL Statement db::name ()->where ("Id=1")->buildsql (); Delivery conditions Db::name () WHERE ("id", 1)->buildsql (), pass the field name, and want to use the value Db::name ()->where ("id", "<>", 1)->buildsql (); The field name, expression, want to determine the value of Db::name ()->where (' id ', ' between ', ' 1,5 ')->buildsql (); IDs between 1-5, including 1 and 5
Db::name ()->where ([' ID ' =>1])->buildsql ();D b::name ()->where ([' ID ' =>[' in ', [1,2,3,4]]]) BuildSQL ();

"Two conditions are the relationship of and"

Db::name ()->where ([' id ' =>1],[' name ' = ' Kaluo '])->buildsql ();


EXP is a conditional expression

Db::name ()->where ("id", "EXP", "Not In ()")->buildsql ();

"Two conditions are the relationship of or"

Db::name ()->where ("id", "in", "No")->whereor (' name ', ' Buld ')->buildsql ();

where () is an array, is a string, is a parameter

# Note Information "The letters are compiled into the following symbols, etc." "condition is case insensitive"
# EQ =
# NEQ <>
# LT <
# ELT <=
# GT >
# EGT >=
# between between * and *
# Notbetween not between * and *
# in In (*,*)
# notin NO TIN (*,*)

Expression::

Betweenin

Chained operation

Db::table ()->where (' id ', ' > ', Ten)->select (); All fields in the queried table

"Field Method"

Db::table ()->where (' id ', ' > ', ten)->field ("Name,id")->select (); The Name,id field in the query table

"Order Method"

Db::table ()->where (' id ', ' > ', ten)->field ("Name,id")->order ("id DESC")->limit (3,5)->select (); Query the Name,id field in the table, flashback sort, starting from the third one, fetch 5

The page Method page (2,5) starts on the second page and displays five articles "

Db::table ()->where (' id ', ' > ', ten)->field ("Name,id")->order ("id DESC")->page (3,5)->select (); Query the Name,id field in the table, flashback sort, start from the third page, fetch 5

"Group Group"

Db::table ()->where (' id ', ' > ', ten)->field ("Name,id")->group ("' Group '")->select (); The Name,id field in the query table, GROUP BY group

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.