Download the PHP package phpfui/orm without Composer
On this page you can find all versions of the php package phpfui/orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package orm
PHPFUI\ORM
PHPFUI\ORM a minimal Object Relational Mapper (ORM) for MySQL, MariaDB and SQLite3
Why another PHP ORM? In writing minimal and fast websites, it was determined that existing PHP ORM solutions were overly complex. PHPFUI\ORM is a little more than 6.7K lines of code in 50 files. It is designed to have a minimal memory footprint and excellent execution times for most database needs.
Performance comparison of PHPFUI\ORM to Eloquent for different SQL implementations.
PHPFUI\ORM is not an attempt to write an abstraction around SQL as other ORMs do, rather it is a way to work with SQL that closely matches the semantics of SQL, with the power of PHP objects. It allows PHP to manipulate SQL queries without having to write SQL in plain text. This is very useful for queries generated via user interfaces where the user is given a lot of flexability in how a query is defined.
Features
- Active Records A fully type checked object interface and implement basic CRUD functionality.
- Active Tables Full table operations (select, update, insert and delete) including support for where, having, limits, ordering, grouping, joins and unions.
- Data Cursors Cursors implement iterable and Countable eliminating the need to read full arrays into memory.
- Validation Fully customizable and translatable backend validation.
- Virtual Fields Supports get and set semantics for any custom or calculated field such as Carbon dates.
- Migrations Simple migrations offer atomic up and down migrations.
- Relations Parent, children, one to one, many to many, and custom relationships.
- Transactions Object based transactions meaning exceptions will not leave an open transacton.
- Type Safe Prevents stupid type errors.
- Injection Safe Uses PDO placeholders and field sanitation to prevent injection attacks.
- Raw SQL Query Support Execute any valid SQL command.
- Multiple Database Support Work with multiple databases simultaneously.
- Multi-Vendor Support Built on PDO with support for MySQL, MariaDB and SQLite.
Usage
Setup
Active Record Example
Active Table Example
Validation Example
Migration Example
Migrations are atomic and can be run in groups or individually up or down.
Type Safety
Exceptions Supported
Exceptions are generated in the following conditions:
- Accessing field or offset that does not exist
- Deleting records without a where condition (can be overridden)
- Incorrect type for Operator (must be an array for IN for example)
- Passing an incorrect type as a primary key
- Invalid join type
- Joining on an invalid table
All of the above exceptions are programmer errors and strictly enforced. Empty queries are not considered errors. SQL may also return Exceptions if invalid fields are used.
Type Conversions
If you set a field to the wrong type, the library logs a warning then converts the type via the appropriate PHP cast.
Multiple Database Support
While this is primarily a single database ORM, you can switch databases at run time. Save the value from $connectionId = \PHPFUI\ORM::addConnection($pdo);
and then call \PHPFUI\ORM::useConnection($db);
to switch. \PHPFUI\ORM::addConnection
will set the current connection.
The programmer must make sure the proper database is currently selected when database reads or writes happen and that any primary keys are correctly handled.
Copy tables example:
Documentation
- [Setup](<https://github.com/phpfui/ORM/blob/main/docs/1. Setup.md>)
- [Active Record](<https://github.com/phpfui/ORM/blob/main/docs/2. Active Record.md>)
- [Active Table](<https://github.com/phpfui/ORM/blob/main/docs/3. Active Table.md>)
- [Cursors](<https://github.com/phpfui/ORM/blob/main/docs/4. Cursors.md>)
- [Virtual Fields](<https://github.com/phpfui/ORM/blob/main/docs/5. Virtual Fields.md>)
- [Migrations](<https://github.com/phpfui/ORM/blob/main/docs/6. Migrations.md>)
- [Validation](<https://github.com/phpfui/ORM/blob/main/docs/7. Validation.md>)
- [Translations](<https://github.com/phpfui/ORM/blob/main/docs/8. Translations.md>)
- [Transactions](<https://github.com/phpfui/ORM/blob/main/docs/9. Transactions.md>)
- [Miscellaneous](<https://github.com/phpfui/ORM/blob/main/docs/10. Miscellaneous.md>)
Full Class Documentation
License
PHPFUI is distributed under the MIT License.
PHP Versions
This library only supports modern versions of PHP which still receive security updates. While we would love to support PHP from the late Ming Dynasty, the advantages of modern PHP versions far out weigh quaint notions of backward compatibility. Time to upgrade.