PHPackages                             aternos/model - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. aternos/model

ActiveLibrary[Database &amp; ORM](/categories/database)

aternos/model
=============

PHP library for simple and complex database models

v5.2.0(1mo ago)185.7k↓37.9%6MITPHPPHP &gt;=8.4CI passing

Since Jan 9Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/aternosorg/php-model)[ Packagist](https://packagist.org/packages/aternos/model)[ RSS](/packages/aternos-model/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (47)Used By (0)

PHP Model
=========

[](#php-model)

*PHP library for simple and complex database models.*

### About

[](#about)

This library was created to provide a flexible, but yet easy to use Model system, which can be used for new projects but also integrated into existing projects. Every part of the library can be overwritten and replaced separately for custom logic.

In contrast to other model libraries, this library is not tied to any specific database backend, instead every model can contain custom logic for accessing different databases, e.g. for a different cache or search backend. Therefore, this library does not provide any provisioning functionality.

**Note: This library is still in development and some features especially regarding more driver functions will be added in the future.**

### Installation

[](#installation)

```
composer require aternos/model

```

Basic usage
-----------

[](#basic-usage)

### Driver

[](#driver)

The library includes some drivers, but you can also create your own drivers and use them in your project or submit them to be added to the library.

Currently included drivers are:

- [Redis](src/Driver/Redis/Redis.php)
- [Mysqli](src/Driver/Mysqli/Mysqli.php)
- [OpenSearch](src/Driver/OpenSearch/OpenSearch.php)

*All of these drivers require additional extensions or packages, see "suggest" in [composer.json](composer.json).*

Most drivers will work out of the box with a local database set up without password, but for most use cases you have to use different credentials. To do that with the included drivers, you can create a new instance and set the credentials using the constructor

```
$driver = new \Aternos\Model\Driver\Mysqli\Mysqli("localhost", 3306, "username", "password");
```

or fluent setters

```
$driver = (new \Aternos\Model\Driver\Mysqli\Mysqli())->setUsername("username")->setPassword("password");
```

or create a new driver class extending the library driver and overwrite the protected credential properties (either in the class itself or in the constructor), e.g.:

```
