Download the PHP package bertugfahriozer/ci4commonmodel without Composer
On this page you can find all versions of the php package bertugfahriozer/ci4commonmodel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bertugfahriozer/ci4commonmodel
More information about bertugfahriozer/ci4commonmodel
Files in bertugfahriozer/ci4commonmodel
Package ci4commonmodel
Short Description With the codeigniter 4 database builder, I combined the general methods I used for myself into a single model.
License MIT
Informations about the package ci4commonmodel
CommonModel Library for CodeIgniter 4
CommonModel is a versatile and reusable model for CodeIgniter 4, designed to simplify common database operations such as selecting, inserting, updating, and deleting records. This library provides methods that support common SQL features like JOINs, WHERE conditions, LIKE filters, ordering, and more.
Features
- Multiple Database Connection Groups
- Select records with flexible conditions (
WHERE,OR WHERE,LIKE) - Insert single or multiple records into the database
- Update and delete records based on conditions
- Join tables for more complex queries
- Supports ordering and pagination
- Easy counting and existence checks for records
- Built-in support for like queries and batch operations
- Table and column management (add, remove, modify)
- Database creation and deletion
Table of Contents
- CommonModel Library for CodeIgniter 4
- Features
- Table of Contents
- Installation
- Usage
- 1. Retrieving Records (
lists) - 2. Inserting Records (
create) - 3. Batch Insert (
createMany) - 4. Updating Records (
edit) - 5. Deleting Records (
remove) - 6. Count Records (
count) - 7. Check Record Existence (
isHave) - 8. Complex Queries (
research) - 9. Table and Database Management
- Get Table List
- Create a New Table
- Remove a Table
- Add Column to Table
- Remove Column from Table
- Rename Table
- Modify Column Info
- Truncate Table
- Get Table Fields
- Create a New Database
- Remove a Database
- Drop Primary Key
- Drop Key
- Drop Foreign Key
- Troubleshooting: Multiple Database Connection Groups
- Root Cause
- Solution
- License
- Author
Installation
To use CommonModel in your CodeIgniter 4 project, follow these steps:
-
Install with Composer:
- Load the model in your controller:
Usage
1. Retrieving Records (lists)
Fetch records from a database table with flexible filters such as WHERE, OR WHERE, LIKE, JOIN, and ordering. Supports limit and pagination.
2. Inserting Records (create)
Insert a single record into the database and return the newly inserted ID.
3. Batch Insert (createMany)
Insert multiple records at once.
4. Updating Records (edit)
Update existing records by specifying the WHERE conditions and the new data.
5. Deleting Records (remove)
Delete records from a table based on WHERE conditions.
6. Count Records (count)
Count the number of records that match a given condition.
7. Check Record Existence (isHave)
Check whether a record exists in a table with a specified condition.
8. Complex Queries (research)
Search records using LIKE queries and filtering by conditions.
9. Table and Database Management
Get Table List
Create a New Table
Remove a Table
Add Column to Table
Remove Column from Table
Rename Table
Modify Column Info
Truncate Table
Get Table Fields
Create a New Database
Remove a Database
Drop Primary Key
Drop Key
Drop Foreign Key
Troubleshooting: Multiple Database Connection Groups
When working with multiple database connections in CodeIgniter 4, defining them in the .env file is not sufficient on its own. Here's an example configuration in .env:
Attempting to connect using:
Will result in the error:
Root Cause
CodeIgniter 4 does not auto-load database groups other than default from the .env file. You must explicitly define custom groups like secondDB in the app/Config/Database.php file.
Solution
To fix this, add a new public array in your app/Config/Database.php:
Once added, \Config\Database::connect('secondDB') will work properly.
License
This project is licensed under the MIT License. See the LICENSE file for more details.