Core\Db db()
Access our database layer with the db() function. It supports method chaining.
<?php
// Run a query to get at least 10 users
$users = db()->select('*')
->from(':user')
->order('user_id ASC')
->limit(10)
->executeRows();
// Get a single user
$user = db()->select('*')->from(':user')->where(['user_id' => 1])->executeRow();
// Insert an entry into the DB
$insert_id = db()->insert(':user', ['user_name' => 'Foo']);
// Update an entry in the DB
db()->update(':user', ['user_name' => 'bar'], ['user_id' => 1]);
// Get the total rows
$total = db()->select('COUNT(*)')->from(':user')->count();
// Joining tables
db()->select('f.*, b.*')
->from(':foo', 'f')
->join(':bar', 'b', 'b.id = f.id')
->executeRow(); |
| Method | Description | Usage | Returns | ||
|---|---|---|---|---|---|
select(string $select)
$select SQL Select | Select statement for sql query |
| object Core\Db | ||
from(string $table [, string $alias] )
$table Database table name. $alias (optional) Table alias. | Define the table in your SELECT query.
|
| object Core\Db | ||
where(array $condition)
$condition SQL condition in an ARRAY format. | Associative array of a conditional statement. Learn more here. |
| object Core\Db |
...