PHPackages                             kitsunecode/datalayer - 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. kitsunecode/datalayer

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

kitsunecode/datalayer
=====================

The data layer is a persistent abstraction component of your database that PDO

v1.0.2(4y ago)04MITPHPPHP &gt;=7.2

Since Jul 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/enosfox/datalayer)[ Packagist](https://packagist.org/packages/kitsunecode/datalayer)[ Docs](https://www.masterkitsune.com)[ RSS](/packages/kitsunecode-datalayer/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (4)Used By (0)

Data Layer @KitsuneCode
=======================

[](#data-layer-kitsunecode)

###### The data layer is a persistent abstraction component of your database that PDO has prepared instructions for performing common routines such as registering, reading, editing, and removing data.

[](#the-data-layer-is-a-persistent-abstraction-component-of-your-database-that-pdo-has-prepared-instructions-for-performing-common-routines-such-as-registering-reading-editing-and-removing-data)

O data layer é um componente para abstração de persistência no seu banco de dados que usa PDO com prepared statements para executar rotinas comuns como cadastrar, ler, editar e remover dados.

About KitsuneCode
-----------------

[](#about-kitsunecode)

###### KitsuneCode is a set of small and optimized PHP components for common tasks. Held by Enos S. S. Silva and the Kitsune team. With them you perform routine tasks with fewer lines, writing less and doing much more.

[](#kitsunecode-is-a-set-of-small-and-optimized-php-components-for-common-tasks-held-by-enos-s-s-silva-and-the-kitsune-team-with-them-you-perform-routine-tasks-with-fewer-lines-writing-less-and-doing-much-more)

KitsuneCode é um conjunto de pequenos e otimizados componentes PHP para tarefas comuns. Mantido por Enos S. S. Silva e a equipe Kitsune. Com eles você executa tarefas rotineiras com poucas linhas, escrevendo menos e fazendo muito mais.

### Highlights

[](#highlights)

- Easy to set up (Fácil de configurar)
- Total CRUD asbtration (Asbtração total do CRUD)
- Create safe models (Crie de modelos seguros)
- Composer ready (Pronto para o composer)
- PSR-2 compliant (Compatível com PSR-2)

Installation
------------

[](#installation)

Data Layer is available via Composer:

```
"kitsunecode/datalayer": "1.0.*"
```

or run

```
composer require kitsunecode/datalayer
```

Documentation
-------------

[](#documentation)

###### For details on how to use the Data Layer, see the sample folder with details in the component directory

[](#for-details-on-how-to-use-the-data-layer-see-the-sample-folder-with-details-in-the-component-directory)

Para mais detalhes sobre como usar o Data Layer, veja a pasta de exemplo com detalhes no diretório do componente

#### connection

[](#connection)

###### To begin using the Data Layer, you need to connect to the database (MariaDB / MySql). For more connections [PDO connections manual on PHP.net](https://www.php.net/manual/pt_BR/pdo.drivers.php)

[](#to-begin-using-the-data-layer-you-need-to-connect-to-the-database-mariadb--mysql-for-more-connections-pdo-connections-manual-on-phpnet)

Para começar a usar o Data Layer precisamos de uma conexão com o seu banco de dados(MariaDB / Mysql). Para ver as conexões possíveis acesse o [manual de conexões do PDO em PHP.net](https://www.php.net/manual/pt_BR/pdo.drivers.php)

```
define("DATA_LAYER_CONFIG", [
    "driver" => "mysql",
    "host" => "localhost",
    "port" => "3306",
    "dbname" => "datalayer_example",
    "username" => "root",
    "passwd" => "",
    "options" => [
        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8, time_zone = '-03:00'",
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
        PDO::ATTR_CASE => PDO::CASE_NATURAL
    ]
]);
```

#### your model

[](#your-model)

###### The Data Layer is based on an MVC structure with the Layer Super Type and Active Record design patterns. Soon to consume it is necessary to create the model of your table and inherit the Data Layer.

[](#the-data-layer-is-based-on-an-mvc-structure-with-the-layer-super-type-and-active-record-design-patterns-soon-to-consume-it-is-necessary-to-create-the-model-of-your-table-and-inherit-the-data-layer)

O Data Layer é baseado em uma estrutura MVC com os padrões de projeto Layer Super Type e Active Record. Logo para consumir é necessário criar o modelo de sua tabela e herdar o Data Layer.

```
class User extends DataLayer
{
    /**
     * User constructor.
     */
    public function __construct()
    {
        //string "TABLE_NAME", array ["REQUIRED_FIELD_1", "REQUIRED_FIELD_2"], string "PRIMARY_KEY", bool "TIMESTAMPS"
        parent::__construct("users", ["first_name", "last_name"]);
    }
}
```

#### find

[](#find)

```
