TP5 Database Operation Methods

Source: Internet
Author: User
Tags lowercase

I. TP5 database Operation methods

1.name () method
Function: Specifies the default data table name (without prefix)
Example: Db::name (' weiba_post ');
Return: DB Object

2.setTable () method
Function: Specifies the default data table name (with prefix)
Example: db::settable (' op_weiba_post ');
Return: DB Object

3.getTable () method
Function: Gets the current or specified name of the data table (prefixed)
Example: db::gettable (' weiba_post '); Returns op_weiba_post with table prefixes and converted to C-style
Db::gettable (); Returns the name of the table set by Settable () (Officially, the "current" table name is returned).
Return: Table name (String)

4.parseSqlTable () method
Role: Replace the __table_name__ string in the SQL statement with a prefixed table name (lowercase) ... This method is generally not used, mainly for the DB class to call itself
Example: Db::p arsesqltable (__weiba_post__); Returns op_weiba_post with a table prefix and converted to lowercase
Return: Table name (String)

5.query () method
Parameters:
1. $sql the command string [required],
2. $bind =[] bind parameter, default empty array [optional],
3. $master =false, the server serial number (master-slave server is valid), if the database does not configure the master-slave server. The DB class ignores this parameter. Generally not available. [Optional]
4. $class = False Returns the value of the processing mode. Default Direct return
True:pdo Object
Class Name: Current Class handling
": Do not do any processing. Direct return

Function: Execute Query return DataSet (query)
Example: Db::query ($sql); Return query Results
Return: Return query result (array or object)

6.execute () method
Parameters: $sql, $bind = [], $getLastInsID = false, $sequence = null
1. $sql the command string [required],
2. $bind =[] bind parameter, default empty array [optional],
3. $getLastInsID whether =false returns the last inserted ID. True returns the number of rows that were affected by the last last insert Id.false. Default is False. [Optional]
4. $sequence =null If you do not specify a sequence name for the parameter sequence, a string that represents the row ID of the last row that was inserted into the database is returned. If a sequence name is specified for the parameter sequence, a string representing the last value retrieved from the specified sequence object is returned. If the current PDO driver does not support this feature, a IM001 SQLSTATE is triggered.

Function: Execute statement (edit)
Example: Db::execute ($sql); Returns the number of an integral type
Return: Returns the result of the edit,

7.getLastInsID () method
Function: Gets the most recently inserted ID
Example: $id = Db::getlastinsid ()
return: ID

8.GETLASTSQL () method
function: Gets the SQL statement of the most recent query
Example: $sql = Db::getlastsql ()
return: SQL command, String type

9.transaction () method php good powerful ...
Parameters: 1. $callback, callback function [optional]
Function: Executes the database transaction, the callback function executes successfully commits the transaction, or the rollback
Example: Db::transaction ($this->update ($data));
Return: Return value of callback function

10.startTrans () method
Role: Open transaction
Example: Db::starttrans ()
Return: Failed return false, success no return value, note false is different from null (= = =)

11.commit () method
Role: Used for non-autocommit status following query submission
Example: Db::commit ()
Return: no return value

12.rollback () method
Role: Transaction rollback
Example: Db::rollback ();
Return: no return value

13.batchQuery () method
Parameters: Just one. The type must be an array. Otherwise, it will return directly to the false
Function: The batch executes the SQL statement, forcing the transaction to be considered an edit operation. That is to say, either all succeeds. Either all fail (failure throws an exception)
Example: Db::batchquery ($arr);//parameter is an array of SQL commands
Return: Always returns True

14.getConfig () method
Function: Returns the database configuration parameters
Example: $config = Db::getconfig ();
Return: Configuration information

15.getPartitionTableName () method
Function: Get the table name of the data table (use it again. maybe to rewrite.)
Example:
Return: Table name

16.value () method
Parameters: 1. field. 2 Default value
Function: Get the value of a field
Example: db::table (' Op_user ')->value (' uid ', false);
Function: Get the value of a field

17.column () method
Parameters:
1. Field name. Multiple separated by commas [required]
2. Indexed fields [optional]
Function: Get an array of a column
Example: Don't want to write
Function: This is the value () method group to ...

18.count () method
Parameters: The default is *, recommended for later use 0
Function: Count query, Quantity
Example: db::table (' Op_user ')->count (0);
Return: Quantity

19.sum () method
Parameters: Default is *. Recommended changes
function: Sum
Example: db::table (' Op_user ')->sum (' uid '); The total number of UID, good magical demand ...
Return: Quantity

20.min () method
Parameters: Default is *. Recommended changes
Function: To find the minimum value
Example: db::table (' Op_user ')->min (' uid '); Minimum UID
Return: Field value

21.max () method
Parameters: Default is *. Recommended changes
Function: Max value
Example: db::table (' Op_user ')->max (' uid '); Maximum UID
Return: Field value

22.avg () method
Parameters: Default is *. Recommended changes
Effect: Averaging
Example: db::table (' Op_user ')->avg (' uid '); Maximum UID
Return: Field value

23.setField () method
Parameter: Can be an array, or it can be a string
Action: Modifies the value of a field (internal call update)
Example:
Db::table (' Op_user ')->where ([' uid ' =>1])->setfield (' phone ', ' 110 ');
Db::table (' Op_user ')->where ([' uid ' =>1])->setfield ([' phone ' = ' 110 ']);
Return: Affects the number of rows

24.SETINC () method
Parameters:
1. $field: Same as SetField (). In the final analysis, call the update
2. $step: Growth value
3. $lazyTime: Delay time is greater than 0 o'clock
Role: Deferred update. Saved in cache. DB class is automatically called.

25.setDec () method
Parameters:
1. $field: Same as SetField (). In the final analysis, call the update
2. $step: Decrease Value
3. $lazyTime: Delay time is greater than 0 o'clock
Function: With Setinc () method

26.join () method
Parameters:
1. Table name, support __weiba_post__,
2.on condition. can be a string. It can also be an array. If the array is connected with an and.
3.join type. Left,right,inner
Note. If only one argument is passed, it must be an array. Format is the above three values, otherwise error.
Role: Correlation Query
Example:
Db::table (' AA ')->join (' __bb__ ', ' aa.id=bb.id and Aa.name=bb.name ', ' left '); AA left JOIN BB on Aa.id=bb.id and Aa.name=bb.name
Db::table (' AA ')->join (' BB ', [' aa.id=bb.id ', ' aa.name=bb.name '], ' left '); AA left JOIN BB on Aa.id=bb.id and Aa.name=bb.name
Db::table (' Op_user as U ')->field (' U.uid ')->join ([' Op_bz_binzhouq ' = ' Q '], ' u.uid = Q.uid ', ' left ') Select (); SELECT u.uid from Op_user as u left joins Op_bz_binzhouq q on u.uid = Q.uid

27.union () method
Parameters:
1. $union, can be an array, or it can be a string
2. $all, a value of union all, otherwise union
Role: Merging result sets
Example: Db::union ($union, true);

28.field () method
Parameters:
1. $field: True all fields, string (Auto-Redo)
2. True or FALSE, whether to go heavy, if $field is the full string (true), does not support the de-weight.
3. $tableName: Table name. The form of a $tablename. $field
There are two parameters behind ... I can't use it.

Role: Specify field fields
Example: Db::field (' ID, name ', 0, ' user ')->field (' PID, pname, Psex ', 0, ' ping ')//user.id, User.Name, Ping.pid, Ping . PName, Ping.psex

29.view () method
Parameters:
1. $join: Table name
2. $field: Field Name
3. $on: Association condition, same join method
4. $type: Association type. left.right

Function: The field set by this method is preceded by a table
Example: db::table (' user ')->field (' uid ', 0, ' user ')->view (' Binzhour ', ' name ', ' User.uid=binzhour.uid ', ' left ') Select ();
Select ' user '. ' uid ', ' binzhour '. ' Name ' from ' user ' to ' left join ' binzhour ' on ' user '. ' uid ' = ' binzhour '. ' UID ';

30.partition () method
Parameters:
1.data,
2.field,
3.rule[Optional]

Function: Sets the Getpartitiontablename () method of the table rule, which is called internally
Example: See Getpartitiontablename method

31.where () method
Parameters:
1.field query fields
2.op[Optional] Query expression
3.condition Query criteria

Function: Specifies and queries the condition. Internally called Parsewhereexp () method,
Example: See Parsewhereexp () method

32.whereOr () method
Parameters: Same where () method
Function: Specifies the or query condition. The only difference from where is to connect with OR. Parsewhereexp () method for internal invocation
Example: See Parsewhereexp () method

33.whereXor () method
Parameters: Same where () method
Effect: XOR, both sides of the same Boolean value is false. The difference is true. Parsewhereexp () method for internal invocation
Example: See Parsewhereexp () method

34.limit () method
Parameters:
1. Starting position
2. Number of queries
Role: Specify the number of queries
Example: Limit (0, 20);

35.page () method
Parameters:
1. pages [Required]
2. Number per page, [optional 20].
Role: Specify paging
Example: page (1,20); First page 20 articles per page.

36.table () method
Parameters:
1. Table name
Function: Specifies the data table for the current operation
Example: Table (' TableName ')

37.using () method (not known usage ...)
Parameters:
1. Field name
Role: Using Support
Example: Select A.*, b.* from a LEFT join B using (ColA); Equivalent to select A.*, b.* from a LEFT join B on a.cola = B.cola;

38.order () method
Parameters:
1. Field name
2. Sorting
Role: Sort
Example: Order (' id ', ' desc ') or order ([' id ' = ' desc ', ' create_time ' = ' desc '])

39.cache () method
Parameters:
1. Cache key.
2. Cache expiration.
Role: Query Caching
Return object ...
Example: Cache (' id ', 10)

40.group () method
Parameters: 1. Field name
Function: Group Query
Example:

41.having () method

42.distinct () method

43.alias () method. Aliases

44.force () method
Parameters: Index Name
Role: Forcing the use of indexes, not using other indexes

45.comment () method
Parameters: Comment Content
Function: Write a comment to the SQL command.
Example: Db::name (' bz_live ')->comment (' good boring method ')->find (); Equivalent to SELECT * from ' op_bz_live ' LIMIT 1/* Good boring method */

46.FETCHSQL () method
Parameter: Write True
function: Returns the SQL statement
Example: $sql = Db::name (' bz_live ')->fetchsql (True)->select ();

47.fetchPdo () method
Parameter: Write True
Function: Returns the Pdostatement object
Example: Db::name (' bz_live ')->fetchpdo (True)->select ();

48.strict () method
Parameter: True/false
Role: Whether to strictly check the field name
Example:

49.failException () method
Parameter: True/false
Role: Setting query data does not exist whether to throw an exception

TP5 Database Operation Methods

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.