Database Query
WeeSpeed supports the following database query methods:
1. Source Explanation
WeeSpeed directly calls the database methods of Medoo. The following is a brief description. For detailed information, please refer to the official documentation.
2. Query Data
select
Query data.
$data = Db::select('table', [
'column1',
'column2'
], [
'column3' => 'value'
]);get
Query a single piece of data.
$data = Db::get('table', [
'column1',
'column2'
], [
'column3' => 'value'
]);has
Check if data exists.
$exists = Db::has('table', [
'column' => 'value'
]);count
Count the number of data items.
$count = Db::count('table', [
'column' => 'value'
]);max
Get the maximum value of a certain column.
$max = Db::max('table', 'column', [
'column2' => 'value'
]);min
Get the minimum value of a certain column.
$min = Db::min('table', 'column', [
'column2' => 'value'
]);avg
Get the average value of a certain column.
$avg = Db::avg('table', 'column', [
'column2' => 'value'
]);sum
Get the sum of a certain column.
$sum = Db::sum('table', 'column', [
'column2' => 'value'
]);3. Insert Data
insert
Insert a single piece of data.
Db::insert('table', [
'column1' => 'value1',
'column2' => 'value2'
]);insertMulti
Insert multiple pieces of data.
Db::insertMulti('table', [
[
'column1' => 'value1',
'column2' => 'value2'
],
[
'column1' => 'value3',
'column2' => 'value4'
]
]);4. Update Data
update
Update data.
Db::update('table', [
'column1' => 'new_value'
], [
'column2' => 'value'
]);5. Delete Data
delete
Delete data.
Db::delete('table', [
'column' => 'value'
]);6. Aggregate Query
query
Execute a custom SQL query.
$data = Db::query('SELECT * FROM table WHERE column = :value', [
':value' => 'value'
])->fetchAll();exec
Execute a custom SQL statement (no return value).
Db::exec('UPDATE table SET column = :value WHERE column2 = :value2', [
':value' => 'new_value',
':value2' => 'value2'
]);7. Transaction Operations
action
Execute a transaction operation.
Db::action(function($database) {
Db::insert('table1', [
'column1' => 'value1'
]);
Db::update('table2', [
'column2' => 'value2'
], [
'column3' => 'value3'
]);
});8. Other Methods
id
Get the ID of the last inserted record.
$lastInsertId = Db::id();info
Get database information.
$info = Db::info();debug
Debug SQL statements.
Db::debug()->select('table', '*');log
Get the query log.
$logs = Db::log();last
Get the last executed SQL statement.
$lastQuery = Db::last();9. Supported Database Types
Medoo supports the following database types:
- MySQL
- MariaDB
- PostgreSQL
- SQLite
- SQL Server
- Oracle
- Sybase