Download the PHP package osemk/php-custom-model without Composer
On this page you can find all versions of the php package osemk/php-custom-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download osemk/php-custom-model
More information about osemk/php-custom-model
Files in osemk/php-custom-model
Package php-custom-model
Short Description PHP CustomModel let's you to convert your MYSQL table automaticly to a PHP Model
License MIT
Informations about the package php-custom-model
PHPCustomModel
PHPCustomModel let's you to convert your MYSQL database tables to a PHP Model automaticly. This library uses mysqli to connect and to request database.
FAQ
- Can I run PHPCustomModel for all MYSQL tables?
- I tried to adopt it to use for all MYSQL tables but it can gives error with tables with non-PRI keys or tables has less identifier columns.
Getting Started
Before you start using this Library, you need to know how PHP works, you need to know how MYSQL work and what is Models. This is a fundamental requirement before you start. Without this knowledge, you will only suffer.
Requirements
Installing PHPCustomModel
PHPCustomModel is installed using Composer.
- Run
composer require osemk/php-custom-model. This will install the latest stable release. - Include the Composer autoload file at the top of your main file:
include __DIR__.'/vendor/autoload.php';
- Make models!
Basic Example
Documentation
PHPCustomModel converts tables to models. A sample database table that name is "employees"
| id | firstname | jobtitle |
|---|---|---|
| 1 | Diane | President |
| 2 | Mary | VP Sales |
| 3 | Jeff | VP Marketing |
| 4 | William | Sales Manager (APAC) |
| 5 | Gerard | Sale Manager (EMEA) |
Using PHPCustomModel we can easily convert this table to a model and we can easily do CRUD processes on table like below.
Bring table
This will fetch row with ID =1 and assign columns to $employee var.
We can check if has a record with ID=1,
Check records
Now the current object includes these;
id=1, firstname=Diane, jobtitle=President
We can change these parameters using model easily like below;
Change parameters
or
and update it;
Update
Now our table looks like below;
| id | firstname | jobtitle |
|---|---|---|
| 1 | Angel | New President |
| 2 | Mary | VP Sales |
| 3 | Jeff | VP Marketing |
| 4 | William | Sales Manager (APAC) |
| 5 | Gerard | Sale Manager (EMEA) |
That is it!
If you want to delete record, use;
Delete
Now our table;
| id | firstname | jobtitle |
|---|---|---|
| 2 | Mary | VP Sales |
| 3 | Jeff | VP Marketing |
| 4 | William | Sales Manager (APAC) |
| 5 | Gerard | Sale Manager (EMEA) |
That is awesome!
Insert New record
Inserting a new row is also easy, just don't send an ID like below,
$employee = new CustomModel("employees",0);
It creates new model from scracth. Now you can add some strings
Now our table look like below;
| id | firstname | jobtitle |
|---|---|---|
| 2 | Mary | VP Sales |
| 3 | Jeff | VP Marketing |
| 4 | William | Sales Manager (APAC) |
| 5 | Gerard | Sale Manager (EMEA) |
| 6 | Onur | King of the World |
Other fetching methods
You can fetch directly using other columns except ids.
it directly fetches id=6 but this column is not an identifier may be there are some records too, so it fetches only latest "Onur" record.
So you can make more unique your request with adding extra columns like below;
Other easy method
The best method for this library is save() method. When you want to change or insert a record to table, you can use save().
So awesome, didn't it?
License
MIT License, © Onur Erginer 2023-present.