https://github.com/kumbiaphp/activerecord
New Active Record for KumbiaPHP
https://github.com/kumbiaphp/activerecord
activerecord hacktoberfest kumbiaphp orm php
Last synced: about 1 year ago
JSON representation
New Active Record for KumbiaPHP
- Host: GitHub
- URL: https://github.com/kumbiaphp/activerecord
- Owner: KumbiaPHP
- License: bsd-3-clause
- Created: 2014-03-10T00:29:15.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2024-10-25T11:28:45.000Z (over 1 year ago)
- Last Synced: 2024-10-29T18:47:51.304Z (over 1 year ago)
- Topics: activerecord, hacktoberfest, kumbiaphp, orm, php
- Language: PHP
- Homepage: https://kumbiaphp.com
- Size: 407 KB
- Stars: 24
- Watchers: 11
- Forks: 11
- Open Issues: 6
-
Metadata Files:
- Readme: README.en.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README

[](https://scrutinizer-ci.com/g/KumbiaPHP/ActiveRecord/)
[](https://scrutinizer-ci.com/g/KumbiaPHP/ActiveRecord/)
[](https://travis-ci.org/KumbiaPHP/ActiveRecord)
[](https://codeclimate.com/github/KumbiaPHP/ActiveRecord)
ENGLISH - [SPANISH](/README.md)
# ActiveRecord
New ActiveRecord in development
Don't use in production
## Install with composer in KumbiaPHP
Requires KumbiaPHP > 0.9RC
* Create file ***composer.json*** in to project root:
```yml
--project
|
|--vendor
|--default
|--core
|--composer.json This is our file
```
* Add the next lines:
```json
{
"require": {
"kumbia/activerecord" : "dev-master"
}
}
```
* Execute command **composer install**
* Continue with steps number 2 and 3 of the next section.
## Install in KumbiaPHP
Requires KumbiaPHP > 0.9RC
1. Copy folder ***lib/Kumbia*** in vendor. (vendor/Kumbia/ActiveRecord/..)
2. Copy [config_databases.php](/config_databases.php) in ***app/config/databases.php*** and set configuration
3. Add in ***app/libs/*** : [lite_record.php](#literecord) and/or [act_record.php](#actrecord)
### LiteRecord
For those who prefer SQL and the advantages of an ORM it includes a mini ActiveRecord
```php
data = People::all();
}
public function find($id) {
$this->data = People::get($id);
}
}
```
### Using LiteRecord methods
#### Filtering data
```php
//get all as array of records
$rows = People::all();
echo $row[0]->name;
//get by primary key as record
$row = People::get($peopleId);
echo $row->name;
//filter as array of records
$rows = People::filter("WHERE name LIKE ?", [$peopleName]);
echo $rows[0]->name;
//filter by sql as record
$row = People::first("SELECT * FROM people WHERE name = :name", [":name" => $peopleName]);
echo $row->name;
//filter by sql as array of records
$rows = People::all("SELECT * FROM people WHERE hire_date >= ?", [$hireDate]);
echo $rows[0]->name;
```
#### DML / Insert, update, delete
```php
//adding a new record
$peopleObj = new People();
$peopleObj->create([
'name' => 'Edgard Baptista',
'job_title' => 'Accountant',
'hire_date' => date('Y-m-d'),
'active' => 1
]); //returns True or False on success or fail
//adding a new record alternative
//please prefer this method by simplicity.
//save executes create method when primary key is missing
//and update ones when it exists
$peopleObj = new People();
$peopleObj->save([
'name' => 'Edgard Baptista',
'job_title' => 'Accountant',
'hire_date' => date('Y-m-d'),
'active' => 1
]); //returns True or False on success or fail
//adding a new record alternative //shorthand method
//passing the data when instantiate the class
$peopleObj = new People([
'name' => 'Edgard Baptista',
'job_title' => 'Accountant',
'hire_date' => date('Y-m-d'),
'active' => 1
]);
$peopleObj->save(); //returns True or False on success or fail
//updating a record
//first find the record to update
$peopleObj = People::get($peopleId);
$peopleObj->update([
'name' => 'Edgard Baptista Jr',
'active' => 0
]); //returns True or False on success or fail
//updating a record alternative
//first find the record to update
$peopleObj = People::get($peopleId);
$peopleObj->save([
'name' => 'Edgard Baptista Jr',
'active' => 0
]); //returns True or False on success or fail
//deleting a record by primary key
People::delete($peopleId);
```