Page tree
Skip to end of metadata
Go to start of metadata


Core\Db db()

Access our database layer with the db() function. It supports method chaining.



// Run a query to get at least 10 users
$users = db()->select('*')
   ->order('user_id ASC')
// 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', ' =')



select(string $select)



SQL Select

Select statement for sql query

// Method chaining
->select('user_id, user_name')
// SQL equivalent
SELECT user_id, user_name

object Core\Db

from(string $table [, string $alias] )



Database table name.


(optional) Table alias.

 Define the table in your SELECT query.

Table Prefix: Be sure to prefix tables with a colon.

 // Method chaining
->from(':user', 'u')

// SQL equivalent
FROM prefix_user AS u
object Core\Db

where(array $condition)



SQL condition in an ARRAY format.

Associative array of a conditional statement.

Learn more here.

// Method chaining
	'user_name' => 'Foo',
	'full_name' => 'Bar'
// SQL equivalent
WHERE user_name = "Foo" AND full_name = "Bar"
object Core\Db


Conditional Array Statements



  • No labels