Db
in component
A wrapper around the OpenCart database object with helper methods for building and running insert, update and select queries.
Table of Contents
Properties
Methods
- __construct() : mixed
- Creates the wrapper around the OpenCart database object.
- getFieldLengths() : array<string|int, mixed>|false
- Returns the maximum lengths of varchar fields in a table. Only varchar(...) fields are supported, others get 0.
- insert() : int|false
- Builds and runs an INSERT (or REPLACE) query from an array. Values are escaped, null becomes NULL, numeric keys are added as raw SQL expressions.
- insertOrUpdate() : int|false
- Inserts a record or updates it when a duplicate key exists (INSERT ... ON DUPLICATE KEY UPDATE).
- query() : array<string|int, mixed>|object
- Runs an SQL query.
- queryFirst() : array<string|int, mixed>
- Deprecated. Runs a query and returns the first row.
- queryHash() : array<string|int, mixed>|false
- Runs a query and returns rows indexed by the value of the given column.
- queryInsert() : int|false
- Deprecated, use insert() instead.
- queryUpdate() : mixed
- Deprecated, use update() instead.
- safeQuery() : mixed
- Runs a query, replacing DB_PREFIX with the MijoShop prefix when MijoShop is present.
- update() : mixed
- Builds and runs an UPDATE query from an array. Values are escaped, null becomes NULL, numeric keys are added as raw SQL expressions.
Properties
$db
protected
mixed
$db
= null
Methods
__construct()
Creates the wrapper around the OpenCart database object.
public
__construct(mixed $db) : mixed
$db — OpenCart database object.
Parameters
- $db : mixed
getFieldLengths()
Returns the maximum lengths of varchar fields in a table. Only varchar(...) fields are supported, others get 0.
public
getFieldLengths(mixed $table, mixed $fields) : array<string|int, mixed>|false
$table — full table name. $fields — list of field names.
Parameters
- $table : mixed
- $fields : mixed
Return values
array<string|int, mixed>|false —Field => length pairs or false if the table or fields are empty.
insert()
Builds and runs an INSERT (or REPLACE) query from an array. Values are escaped, null becomes NULL, numeric keys are added as raw SQL expressions.
public
insert(mixed $tbl, mixed $arr[, mixed $is_replace = false ][, mixed $update_on_duplicate = false ]) : int|false
$tbl — table name without DB_PREFIX. $arr — field => value pairs. $is_replace — use REPLACE instead of INSERT. $update_on_duplicate — add ON DUPLICATE KEY UPDATE with the same values.
Parameters
- $tbl : mixed
- $arr : mixed
- $is_replace : mixed = false
- $update_on_duplicate : mixed = false
Tags
Return values
int|false —Last insert id or false on failure.
insertOrUpdate()
Inserts a record or updates it when a duplicate key exists (INSERT ... ON DUPLICATE KEY UPDATE).
public
insertOrUpdate(mixed $table, mixed $data) : int|false
$table — table name without DB_PREFIX. $data — field => value pairs.
Parameters
- $table : mixed
- $data : mixed
Return values
int|false —Last insert id or false on failure.
query()
Runs an SQL query.
public
query(mixed $sql) : array<string|int, mixed>|object
$sql — SQL query.
Parameters
- $sql : mixed
Return values
array<string|int, mixed>|object —Array of result rows, or the original result object when there are no rows.
queryFirst()
Deprecated. Runs a query and returns the first row.
public
queryFirst(mixed $qry) : array<string|int, mixed>
$qry — SQL query.
Parameters
- $qry : mixed
Return values
array<string|int, mixed> —First row of the result.
queryHash()
Runs a query and returns rows indexed by the value of the given column.
public
queryHash(mixed $qry_string, mixed $key) : array<string|int, mixed>|false
$qry_string — SQL query. $key — column whose value is used as the array key.
Parameters
- $qry_string : mixed
- $key : mixed
Tags
Return values
array<string|int, mixed>|false —Rows indexed by the key or false if there are no rows.
queryInsert()
Deprecated, use insert() instead.
public
queryInsert(mixed $tbl, mixed $arr[, mixed $is_replace = false ]) : int|false
$tbl — table name without DB_PREFIX. $arr — field => value pairs. $is_replace — use REPLACE instead of INSERT.
Parameters
- $tbl : mixed
- $arr : mixed
- $is_replace : mixed = false
Return values
int|false —Last insert id or false on failure.
queryUpdate()
Deprecated, use update() instead.
public
queryUpdate(mixed $tbl, mixed $arr[, mixed $where = '' ]) : mixed
$tbl — table name without DB_PREFIX. $arr — field => value pairs. $where — WHERE condition without the WHERE keyword.
Parameters
- $tbl : mixed
- $arr : mixed
- $where : mixed = ''
safeQuery()
Runs a query, replacing DB_PREFIX with the MijoShop prefix when MijoShop is present.
public
safeQuery(mixed $query) : mixed
$query — SQL query.
Parameters
- $query : mixed
Return values
mixed —Result of the database query.
update()
Builds and runs an UPDATE query from an array. Values are escaped, null becomes NULL, numeric keys are added as raw SQL expressions.
public
update(mixed $tbl, mixed $arr[, mixed $where = '' ]) : mixed
$tbl — table name without DB_PREFIX. $arr — field => value pairs. $where — WHERE condition without the WHERE keyword; empty updates all rows.
Parameters
- $tbl : mixed
- $arr : mixed
- $where : mixed = ''
Tags
Return values
mixed —Result of the database query.