Database Custom Query
Method Name: Bd::query ()
Parameter explanation:
$SQL: Custom SQL statements
$ARG: Data that needs to be bound
$unbuffered: Whether to use no cache queries
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php Db::Query("SELECT * from%t WHERE ID in (%n)",Array( ' test_db ',Array(1,2,3) ));
Resource Set Transformation result set Whlie($res= DB::Fetch( $query ) { < Span class= "RE0" > $result [] = $res Debug ( $result //custom Delete id=11 data Db::query ( "delete from%t where did = %d" ,array ( ' test_db ' ,< Span class= "nu0" >9 ) ; ?> |
Resource Set Transformation result set
Method Name: Db::fetch ()
Parameter explanation:
$resourceid: Query resource for database queries
$type: Array type
Associated Index
1 2 3 4 5 |
Resource Set Transformation result set Whlie($res = DB::fetch($query)){ $result[] = $res; } Debug($result) |
Numeric index
1 2 3 4 5 6 7 8 9 10 |
<?php $data= DB::Query("SELECT * from%t where do in (%n)",Array( ' test_db ',Array(1,2,3,5) while ( $res = db::fetch ($ Data,mysql_num) { $result [] = $res } print_r $result ?> |
Digital index and associated index all out
1 2 3 4 5 6 7 8 9 10 |
<?php $data= DB::Query("SELECT * from%t where do in (%n)",Array( ' test_db ',Array(1,2,3,5) ));
while($res = DB::fetch($data, Mysql_both)){ $result[] = $res; } Print_r ($result); ?> |
Converting a single-field resource set to a result set
Parameter explanation:
$resourceid: Query resource for database queries
$row: Specify the first field of a row
1 2 3 4 5 6 7 8 9 |
<?php $query= DB::Query("SELECT * from%t where do in (%n)",Array( ' test_db ',array(1,2,3,5) ));
$data = DB::result($query,0);
echo $data; ?> |
Resource Set Row Count
Method Name: Db::num_rows ()
Parameter explanation:
$resourceid: Query resource for database queries
1 2 3 4 5 6 7 8 9 10 |
<?php //small amount of data with num_rows, big Data with COUNT (*) $query = db::query ( "select * from%t WHERE ID > %d" , Array ( ' test_db ' , 7 ) $data = db::num_rows< Span class= "Br0" > ( $query echo $data ?> |
Resource Set Resource release
Method Name: Db::free_result ()
Parameter explanation:
$query: Query resource that executes the SQ statement
1 2 3 4 5 6 7 8 9 |
<?php $query= DB::query ( "SELECT COUNT (*) from%t WHERE ID < %d order by id" ,array ( < Span class= "st_h" > ' test_db ' , 7 ) $data = db::result $query Db::free_result ( $query echo $data ?> |
Sort by field
Method Name: Db::order ()
Parameter explanation:
$field: Fields that need to be sorted
$order: How to sort
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php Reverse order $query= DB::Query("SELECT * from%t where did <%d ORDER BY ". Db::Order(' Did ',' DESC '),Array( ' test_db ', 8 ));
while($res = DB::fetch($query)){ $result[] = $res; }
Debug($result); ?> |
Value Interval Setting
Method Name: Db::limit ()
Parameter explanation:
$start: The starting index value
$limit: Number of entries
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php Use Db::limit () to remove the 2,3,4 bar data, such as the first 3 to write Db::limit (3) $query= DB::Query("SELECT COUNT (*) from%t WHERE ID <%d ORDER by ". Db::Order(' ID ',' DESC '). Db::Limit(2,3,4),array( ' test_db ', 10 ));
Whlie($res = DB::fetch(%query)){ $result[] = $res; }
Debug($result) ?> |
Field stitching
Method Name: Bd::implode ()
Parameter explanation:
$array: Array of fields to stitch
$glue: String for field stitching
1 2 3 |
<?php DB::implode(array(' id ' = ', ' name ' = ' ddd ') ), ' and '); ?> |
Change ID to 13,name value to CCC
1 2 3 4 5 6 7 8 9 |
<?php Db::Query("Update%t Set". Db::implode (array ( Dname ' => ' CCC ' ' did ' => ' " ) . where did=%d ' ,array ( ' test_db ' 8 ) ?> |
field data settings
Method Name: Db::field ()
Parameter explanation:
$field: The name of the field to be processed
$val: The value of the field
$glue: Types of connection fields and values
1 2 3 4 5 6 |
<?php //id=3 changed to id=99 Db::query ( "update%t set" ::field ( ' did ' ,< Span class= "st_h" > ' , ' = ' ) .%d ",array ( test_db ' ,3) ?> |
discuz! Operation of the X3.1 database (ii)