CommonModel
in package
Table of Contents
Properties
- $db : mixed
Methods
- __construct() : mixed
- count() : int
- Counts the number of records in the specified table that match the given conditions.
- create() : int
- Inserts a new record into the specified table and returns the insert ID.
- createMany() : mixed
- Inserts multiple records into the specified table.
- edit() : bool
- Updates records in the specified table based on the given conditions.
- isHave() : int
- Checks if there are any records in the specified table that match the given conditions.
- lists() : array<string|int, mixed>|null|false
- notWhereInList() : object
- Retrieves records from the specified table, excluding those where the given key matches any value in the specified array, with optional joins and sorting.
- remove() : bool
- Deletes records from the specified table based on the given conditions.
- research() : object
- Retrieves records from the specified table that match the given conditions and like patterns.
- selectOne() : object|null
- Selects a single record from the database based on conditions.
- truncateTable() : bool
- Truncates the specified table, removing all records while keeping the table structure intact.
- whereInCheckData() : int
- Checks if there are records in the table where a specified column's value matches any of the provided values.
- whereWithJoins() : object
- Retrieves records from the specified table with optional joins, where conditions, like conditions, and ordering, with pagination support.
Properties
$db
public
mixed
$db
Methods
__construct()
public
__construct([string $group = 'default' ]) : mixed
Parameters
- $group : string = 'default'
count()
Counts the number of records in the specified table that match the given conditions.
public
count(string $table[, array<string|int, mixed> $where = [] ]) : int
Parameters
- $table : string
- $where : array<string|int, mixed> = []
Tags
Return values
int —Returns the count of rows that match the condition
create()
Inserts a new record into the specified table and returns the insert ID.
public
create(string $table[, array<string|int, mixed> $data = [] ]) : int
This method allows you to insert a new record into a database table. After the record is inserted, it returns the ID of the inserted row.
Parameters
- $table : string
- $data : array<string|int, mixed> = []
Tags
Return values
int —Returns the ID of the newly inserted record. If the table doesn't have an auto-incremented primary key, it may return 0.
createMany()
Inserts multiple records into the specified table.
public
createMany(string $table, array<string|int, mixed> $data) : mixed
This method inserts an array of data into the table in a batch operation. It is useful for bulk inserts where multiple rows need to be added simultaneously.
Parameters
- $table : string
-
The name of the table where the records will be inserted.
- $data : array<string|int, mixed>
-
A multi-dimensional array where each sub-array represents a row of data to insert. Each sub-array's keys should match the column names. Example: [['name' => 'John', 'email' => 'john@example.com'], ['name' => 'Jane', 'email' => 'jane@example.com']].
Tags
Return values
mixed —Returns true on success, false on failure, or the number of rows inserted (based on the database driver used).
edit()
Updates records in the specified table based on the given conditions.
public
edit(string $table[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $where = [] ]) : bool
This method updates one or more rows in the table where the specified conditions match.
The $data
array contains the new values for the columns, and the $where
array specifies the conditions to find the records to update.
Parameters
- $table : string
-
The name of the table where the records will be updated.
- $data : array<string|int, mixed> = []
-
An associative array of column-value pairs that represent the new values. Example: ['name' => 'John', 'email' => 'john@example.com'].
- $where : array<string|int, mixed> = []
-
An associative array of conditions used to filter the records to be updated. Example: ['id' => 1].
Tags
Return values
bool —Returns true if the update was successful, false otherwise.
isHave()
Checks if there are any records in the specified table that match the given conditions.
public
isHave(string $table, array<string|int, mixed> $where) : int
Parameters
- $table : string
- $where : array<string|int, mixed>
Tags
Return values
int —Returns the number of rows that match the condition.
lists()
public
lists(string $table[, string $select = '*' ][, array<string|int, mixed> $where = [] ][, string $order = 'id ASC' ][, int $limit = 0 ][, int $pkCount = 0 ][, array<string|int, mixed> $like = [] ][, array<string|int, mixed> $orWhere = [] ][, array<string|int, mixed> $joins = [] ][, array<string|int, mixed> $options = ['isReset' => false] ]) : array<string|int, mixed>|null|false
Parameters
- $table : string
-
// table name
- $select : string = '*'
-
// Coluns to select
- $where : array<string|int, mixed> = []
-
// Where conditions
- $order : string = 'id ASC'
-
// Sorting criteria
- $limit : int = 0
-
// Limit on the number of results
- $pkCount : int = 0
-
// Primary key count
- $like : array<string|int, mixed> = []
-
// Like conditions
- $orWhere : array<string|int, mixed> = []
-
// Or conditions
- $joins : array<string|int, mixed> = []
-
// Join operations
- $options : array<string|int, mixed> = ['isReset' => false]
Tags
Return values
array<string|int, mixed>|null|false —Returns the result object on success, null if no results, or false on failure.
notWhereInList()
Retrieves records from the specified table, excluding those where the given key matches any value in the specified array, with optional joins and sorting.
public
notWhereInList(string $table[, string $select = '*' ][, array<string|int, mixed> $joins = [] ], string $whereInKey, array<string|int, mixed> $whereInData[, string $orderBy = 'queue ASC' ]) : object
Parameters
- $table : string
-
The name of the table to query.
- $select : string = '*'
-
Columns to select, separated by commas. Defaults to '*' to select all columns.
- $joins : array<string|int, mixed> = []
-
Array of join conditions, where each element is an associative array with keys 'table', 'cond', and 'type' for the join table, condition, and type respectively.
- $whereInKey : string
-
The column to check for exclusion based on the values in $whereInData.
- $whereInData : array<string|int, mixed>
-
An array of values that should be excluded from the results.
- $orderBy : string = 'queue ASC'
-
Column and direction by which to order the results, defaults to 'queue ASC'.
Tags
Return values
object —Returns an object containing the result set.
remove()
Deletes records from the specified table based on the given conditions.
public
remove(string $table[, array<string|int, mixed> $where = [] ]) : bool
This method deletes one or more rows in the table where the specified conditions match.
The $where
array is used to specify the conditions for finding the records to be deleted.
Parameters
- $table : string
-
The name of the table from which the records will be deleted.
- $where : array<string|int, mixed> = []
-
An associative array of conditions used to filter the records to be deleted. Example: ['id' => 1].
Tags
Return values
bool —Returns true if the delete operation was successful, false otherwise.
research()
Retrieves records from the specified table that match the given conditions and like patterns.
public
research(string $table[, array<string|int, mixed> $like = [] ][, string $select = '*' ][, array<string|int, mixed> $where = [] ]) : object
Parameters
- $table : string
-
The name of the table to query.
- $like : array<string|int, mixed> = []
-
Associative array of LIKE conditions, where the keys are column names and the values are the search patterns.
- $select : string = '*'
-
Columns to select, separated by commas. Defaults to '*' to select all columns.
- $where : array<string|int, mixed> = []
-
Associative array of WHERE conditions.
Tags
Return values
object —Returns an object containing the result set.
selectOne()
Selects a single record from the database based on conditions.
public
selectOne(string $table[, array<string|int, mixed> $where = [] ][, string $select = '*' ][, string $order = 'id ASC' ]) : object|null
Parameters
- $table : string
- $where : array<string|int, mixed> = []
- $select : string = '*'
- $order : string = 'id ASC'
Tags
Return values
object|null —Returns the row object on success or null if no result is found.
truncateTable()
Truncates the specified table, removing all records while keeping the table structure intact.
public
truncateTable(string $table) : bool
Parameters
- $table : string
-
The name of the table to truncate.
Tags
Return values
bool —Returns true on success, false on failure.
whereInCheckData()
Checks if there are records in the table where a specified column's value matches any of the provided values.
public
whereInCheckData(string $att, string $table[, array<string|int, mixed> $where = [] ]) : int
Parameters
- $att : string
- $table : string
- $where : array<string|int, mixed> = []
Tags
Return values
int —Returns the number of rows that match the condition
whereWithJoins()
Retrieves records from the specified table with optional joins, where conditions, like conditions, and ordering, with pagination support.
public
whereWithJoins(string $table[, string $select = '*' ][, array<string|int, mixed> $joins = [] ][, array<string|int, mixed> $where = [] ][, string $order = 'id ASC' ][, int $limit = 0 ][, int $pkCount = 0 ][, array<string|int, mixed> $like = [] ][, array<string|int, mixed> $orWhere = [] ]) : object
Parameters
- $table : string
-
The name of the table to query.
- $select : string = '*'
-
The columns to select, separated by commas. Defaults to '*' to select all columns.
- $joins : array<string|int, mixed> = []
-
Array of join conditions, where each element is an associative array with keys 'table', 'cond', and 'type' for the join table, condition, and type respectively.
- $where : array<string|int, mixed> = []
-
An array of conditions to filter the records by.
- $order : string = 'id ASC'
-
The column and direction to order the results by, defaults to 'id ASC'.
- $limit : int = 0
-
The maximum number of records to return, defaults to 0 (no limit).
- $pkCount : int = 0
-
The number of records to skip (for pagination), defaults to 0.
- $like : array<string|int, mixed> = []
-
An array of 'like' conditions for partial matching. Can contain multiple conditions.
- $orWhere : array<string|int, mixed> = []
-
An array of 'or' conditions for additional filtering.
Tags
Return values
object —Returns an object containing the result set.