$db
$db
lists(string $table, string $select = '*', array $where = [], string $order = 'id ASC', int $limit, int $pkCount, array $like = [], array $orWhere = [], array $joins = [], array $options = ['isReset' => false]) : array|null|false
| string | $table | // table name |
| string | $select | // Coluns to select |
| array | $where | // Where conditions |
| string | $order | // Sorting criteria |
| int | $limit | // Limit on the number of results |
| int | $pkCount | // Primary key count |
| array | $like | // Like conditions |
| array | $orWhere | // Or conditions |
| array | $joins | // Join operations |
| array | $options |
Returns the result object on success, null if no results, or false on failure.
create(string $table, array $data = []) : int
Inserts a new record into the specified table and returns the insert ID.
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.
| string | $table | |
| array | $data |
Returns the ID of the newly inserted record. If the table doesn't have an auto-incremented primary key, it may return 0.
createMany(string $table, array $data) : mixed
Inserts multiple records into the specified table.
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.
| string | $table | The name of the table where the records will be inserted. |
| array | $data | 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']]. |
If the $data array is empty or invalid.
Returns true on success, false on failure, or the number of rows inserted (based on the database driver used).
edit(string $table, array $data = [], array $where = []) : bool
Updates records in the specified table based on the given conditions.
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.
| string | $table | The name of the table where the records will be updated. |
| array | $data | An associative array of column-value pairs that represent the new values. Example: ['name' => 'John', 'email' => 'john@example.com']. |
| array | $where | An associative array of conditions used to filter the records to be updated. Example: ['id' => 1]. |
Returns true if the update was successful, false otherwise.
remove(string $table, array $where = []) : bool
Deletes records from the specified table based on the given conditions.
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.
| string | $table | The name of the table from which the records will be deleted. |
| array | $where | An associative array of conditions used to filter the records to be deleted. Example: ['id' => 1]. |
If the $where array is empty or invalid.
Returns true if the delete operation was successful, false otherwise.
selectOne(string $table, array $where = [], string $select = '*', string $order = 'id ASC') : object|null
Selects a single record from the database based on conditions.
| string | $table | |
| array | $where | |
| string | $select | |
| string | $order |
Returns the row object on success or null if no result is found.
whereInCheckData(string $att, string $table, array $where = []) : int
Checks if there are records in the table where a specified column's value matches any of the provided values.
| string | $att | |
| string | $table | |
| array | $where |
Returns the number of rows that match the condition
isHave(string $table, array $where) : int
Checks if there are any records in the specified table that match the given conditions.
| string | $table | |
| array | $where |
Returns the number of rows that match the condition.
count(string $table, array $where = [], array $like = [], string $select = '', bool $distinct = false) : int
Counts the number of records in the specified table that match the given conditions.
| string | $table | |
| array | $where | |
| array | $like | Optional. Associative array of LIKE conditions. |
| string | $select | Optional. Columns to select. |
| bool | $distinct | Optional. Whether to apply DISTINCT. |
Returns the count of rows that match the condition
research(string $table, array $like = [], string $select = '*', array $where = []) : object|null
Retrieves records from the specified table that match the given conditions and like patterns.
| string | $table | The name of the table to query. |
| array | $like | Associative array of LIKE conditions, where the keys are column names and the values are the search patterns. |
| string | $select | Columns to select, separated by commas. Defaults to '*' to select all columns. |
| array | $where | Associative array of WHERE conditions. |
If the parameters are invalid.
Returns the row object on success or null if no result is found.
notWhereInList(string $table, string $select = '*', array $joins = [], string $whereInKey = '', array $whereInData = [], string $orderBy = 'queue ASC') : object|null
Retrieves records from the specified table, excluding those where the given key matches any value in the specified array, with optional joins and sorting.
| string | $table | The name of the table to query. |
| string | $select | Columns to select, separated by commas. Defaults to '*' to select all columns. |
| array | $joins | 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. |
| string | $whereInKey | The column to check for exclusion based on the values in $whereInData. |
| array | $whereInData | An array of values that should be excluded from the results. |
| string | $orderBy | Column and direction by which to order the results, defaults to 'queue ASC'. |
If the parameters are invalid.
Returns the row object on success or null if no result is found.
getTableList() : array
Retrieves the list of tables in the database.
Returns an array of table names.
newTable(string $table, array $fields, array $addKeys = ['keys' => [], 'primary' => false, 'unique' => false, 'keyName' => ''], array $foreignKeyFilled = ['field' => '', 'referenceTable' => '', 'referenceField' => '', 'onDelete' => '', 'onUpdate' => '', 'fkName' => '']) : bool
Creates a new table in the database with the specified fields and options.
| string | $table | The name of the table to create. |
| array | $fields | An associative array of fields and their data types. |
| array | $addKeys | Optional keys to add to the table. |
| array | $foreignKeyFilled | Optional foreign key constraints. |
If the parameters are invalid.
Returns true on success, false on failure.
removeTable(string $table) : bool
Removes the specified table from the database.
| string | $table | The name of the table to remove. |
If the table name is invalid or not provided.
Returns true on success, false on failure.
addColumnToTable(string $table, array $fields) : bool
Adds a new column to the specified table.
| string | $table | The name of the table to modify. |
| array | $fields | An associative array of fields and their data types. |
If the parameters are invalid.
Returns true on success, false on failure.
removeColumnFromTable(string $table, array $fields) : bool
Removes the specified columns from the table.
| string | $table | The name of the table to modify. |
| array | $fields | An array of column names to remove. |
If the parameters are invalid.
Returns true on success, false on failure.
updateTableName(string $oldName, string $newName) : bool
Updates the name of the specified table.
| string | $oldName | The current name of the table. |
| string | $newName | The new name for the table. |
If the parameters are invalid.
Returns true on success, false on failure.
modifyColumnInfos(string $table, array $fields) : bool
Modifies the column information of the specified table.
| string | $table | The name of the table to modify. |
| array | $fields | An associative array of fields and their new data types. |
If the parameters are invalid.
Returns true on success, false on failure.
emptyTableDatas(string $table) : bool
Truncates the specified table, removing all records while keeping the table structure intact.
| string | $table | The name of the table to truncate. |
If the table name is invalid or not provided.
Returns true on success, false on failure.
getTableFields(string $tableName) : array
Retrieves the fields of the specified table.
| string | $tableName | The name of the table to retrieve fields from. |
If the table name is invalid or not provided.
Returns an array of field objects.
newDatabase(string $dbName) : bool
Creates a new database with the specified name.
| string | $dbName |
If the database name is invalid or not provided.
removeDatabase(string $dbName) : bool
Removes the specified database.
| string | $dbName | The name of the database to remove. |
If the database name is invalid or not provided.
Returns true on success, false on failure.
drpPrimaryKey(string $tableName) : bool
Drop a primary key to the specified table.
| string | $tableName | The name of the table to modify. |
If the parameters are invalid.
Returns true on success, false on failure.
drpKey(string $tableName, string $keyName, bool $prefixKeyName = true) : bool
Drop a key to the specified table.
| string | $tableName | The name of the table to modify. |
| string | $keyName | The name of the key to drop. |
| bool | $prefixKeyName | Whether to prefix the key name with the table name. |
If the parameters are invalid.
Returns true on success, false on failure.
drpForeignKey(string $tableName, string $foreignKeyName) : bool
Drop a foreign key to the specified table.
| string | $tableName | The name of the table to modify. |
| string | $foreignKeyName | The name of the foreign key to drop. |
If the parameters are invalid.
Returns true on success, false on failure.