1. Database Configuration
2. Query execute original ecological SQL statement Additions and deletions
$result = Db::execute (' INSERT into log (user_id, IP) ' VALUES (1, 11231) ');d UMP ($result); $result = Db::query (' select * from lo G '); Echo ' <pre> '; var_dump ($result);
3. parameter-bound named placeholder bindings
$str = ' INSERT into log (user_id, IP) VALUES (?,?) '; $result = Db::execute ($str, [1, ' 12312 ']), $result = Db::query (' select * from log where id =? ', [4]);//Placeholder Db::execute (' ins ert into log (user_id, IP) VALUES (: user_id,: IP) ', [' user_id ' =>12, ' ip ' = ' 5555 ']);
4. Query Builder
Added: db::table (' log ')->insert ([' user_id ' =>1, ' ip ' = ' 654321 ']);//update db::table (' log ') ->where (' id ') , ->update ([' user_id ' =>123]);//query data $list = db::table (' log ') ->where (' id ', ')->select ();//delete data db::table (' log ') ->where (' id ', ten) ->delete ();
To query a table without prefixing the method:
Db::name (' log ')->insert ([' user_id ' =>44, ' IP ' =>5555]);
5. DB chain-operated
Ways to support chained queries:
Method name |
Description |
Select |
Querying the database |
Find |
Querying individual records |
Insert |
Insert record |
Update |
Update record |
Dalete |
Delete Record |
value |
Query value |
column |
Query column |
Chunk |
Block query |
Count |
Aggregate query |
6. Things to support
Automatic control of Things db::transaction (function () { db::table (' log ')->delete (2); Db::table (' log ')->insert ([' user_id ' =>123]); /manually control the submission of things//Start things Db::starttrans (); try { db::table (' log ') ->where (2); Db::table (' log ') ->insert ([' user_id ' = 213]); Db::commit ();} catch (Exception $e) { db::rollback ();}
This article explains about the THINKPHP5 database operation, more relevant content please pay attention to the PHP Chinese network.