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

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

vresende/datalayer
==================

Datalayer is a Datalayer-based SQL Server database abstraction component

1.6(6y ago)031MITPHPPHP ^7.2

Since Oct 15Pushed 6y ago1 watchersCompare

[ Source](https://github.com/vresende/datalayer)[ Packagist](https://packagist.org/packages/vresende/datalayer)[ Docs](http://www.foxmarketingdigital.com.br)[ RSS](/packages/vresende-datalayer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (7)Used By (0)

Data Layer SQlServer
====================

[](#data-layer-sqlserver)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

###### 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 (SQL SERVER) que usa PDO com prepared statements para executar rotinas comuns como cadastrar, ler, editar e remover dados.

### 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:

```
"vresende/datalayer": "^1.5.3"
```

or run

```
composer require vresende/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 (SQL Server). For more connections [PDO connections manual on PHP.net](https://www.php.net/manual/pt_BR/pdo.drivers.php)

Para começar a usar o Data Layer precisamos de uma conexão com o seu banco de dados (SQL Server). 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", [
    "host" => "localhost",
    "port" => "3306",
    "dbname" => "datalayer_example",
    "username" => "root",
    "passwd" => "",
    "options" => [
        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
        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.

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)

```
