• PHP reference

DB

class DB

Class DB.

A basic database interface using MySQLi.

Properties

string $database

Methods

__construct(string|Application|object $database = null)

DB constructor.

Parameters

Exceptions

DB|DB select($table, array $where = [], boolean $limit = false, boolean $order = false, string $where_mode = 'AND', string|array $select_fields = '*')

Do a 'SELECT FROM' query.

Parameters

  • $table
  • array $where
  • boolean $limit
  • boolean $order
  • string $where_mode
  • string|array $select_fields

Return Value

DB query($query, boolean $last = false)

Execute a query in the current MySQL database.

Parameters

  • $query
  • boolean $last

Return Value

integer num(string $table = null, array|string $where = [], integer|boolean $limit = false, string|boolean $order = false, string $where_mode = 'AND')

Do a 'SELECT COUNT(*) FROM' query.

Parameters

  • string $table
  • array|string $where
  • integer|boolean $limit
  • string|boolean $order
  • string $where_mode

Return Value

  • integer

boolean table_exists(string $name)

Check if a table with a specific name exists.

Parameters

  • string $name

Return Value

  • boolean

DB|boolean|string insert(string $table, array $fields = [], boolean $appendix = false, boolean $ret = false)

Insert a row into a table.

Parameters

  • string $table
  • array $fields
  • boolean $appendix
  • boolean $ret

Return Value

  • DB|boolean|string

DB|boolean update(string $table, array $fields = [], array $where = [], boolean $limit = false, boolean $order = false)

Update one or more rows in a table.

Parameters

  • string $table
  • array $fields
  • array $where
  • boolean $limit
  • boolean $order

Return Value

  • DB|boolean

DB|boolean delete($table, array $where = [], string $where_mode = 'AND', boolean $limit = false, boolean $order = false)

Delete one or more rows in a table.

Parameters

  • $table
  • array $where
  • string $where_mode
  • boolean $limit
  • boolean $order

Return Value

  • DB|boolean

stdClass[] result(string $key_field = null, boolean $unserialize = true)

Returns the result of the last executed query as an array of objects.

Parameters

  • string $key_field
  • boolean $unserialize

Return Value

array[] result_array()

Returns the result of the last executed query as an array of arrays.

Return Value

  • array[]

stdClass|null row(integer $r)

Returns a single row returned by the last executed query as an object.

Parameters

  • integer $r Row number, defaults to 0

Return Value

array|null row_array(integer $r)

Returns a single row returned by the last executed query as an object.

Parameters

  • integer $r Row number, defaults to 0

Return Value

  • array|null

integer count()

Returns the number of rows returned by the last executed query.

Return Value

  • integer

integer affected()

Returns the number of rows affected by the last executed query.

Return Value

  • integer

integer|string id()

Returns the autoincrement ID (primary key) of the last inserted row.

Return Value

  • integer|string

string getLastQuery()

Returns the last executed query.

Return Value

  • string

string escape($str)

Escape a string.

Parameters

  • $str

Return Value

  • string

string error()

Get the last error.

Return Value

  • string

static string esc($string)

Escape a string. Alias of: DB::instance()->escape($string).

Parameters

  • $string

Return Value

  • string

final static DB instance(string|Application|object $database = null)

Get an instance of the database.

Parameters

Return Value

Exceptions