PHPackages                             bmorais/database - 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. bmorais/database

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

bmorais/database
================

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

v2.0.12(3mo ago)3385↓100%1[1 issues](https://github.com/brunobmorais/php-database/issues)MITPHPPHP &gt;=8.0

Since Jun 11Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/brunobmorais/php-database)[ Packagist](https://packagist.org/packages/bmorais/database)[ Docs](https://www.bmorais.com)[ RSS](/packages/bmorais-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (102)Used By (0)

Database BMORAIS Code
=====================

[](#database-bmorais-code)

[![Maintainer](https://camo.githubusercontent.com/61bbc602b585f7553199c15226668f871c57b5337db6b2d1d2b47e28fadad47d/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65722d406272756e6f626d6f726169732d626c75652e7376673f7374796c653d666c61742d737175617265)](https://linkedin.com/in/brunobmorais)[![Source Code](https://camo.githubusercontent.com/41ec61cdcee5d25cf5714f442f241878de461a8ec781eb7d122d04e4aa0dc531/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d626d6f726169732f64617461626173652d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/brunobmorais/php-database)[![PHP from Packagist](https://camo.githubusercontent.com/b1bd67cea151732053cf678d407b4eb196d87c398924aae45498e418dfb8f79f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f626d6f726169732f64617461626173652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bmorais/database)[![Latest Version](https://camo.githubusercontent.com/da58cf8d4ac2387580f531fe917ca2dc185466776c6b7fadba6a5f814b5c37ba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6272756e6f626d6f726169732f7068702d64617461626173652e7376673f7374796c653d666c61742d737175617265)](https://github.com/brunobmorais/php-database/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Quality Score](https://camo.githubusercontent.com/d56f29e73c570da6f8d5dc82ffe2e76e033dc7fd17eceab6e2955f81eb15f763/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6272756e6f626d6f726169732f7068702d64617461626173652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/brunobmorais/php-database)[![Total Downloads](https://camo.githubusercontent.com/f32d109b61de4f3b433c9b947dc990bd2b27e65d4ba682c164187de70fbd4f1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626d6f726169732f64617461626173652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bmorais/database)

###### The database 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-database-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 database é 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 BMorais Code
------------------

[](#about-bmorais-code)

###### BMorais Code is a set of small and optimized PHP components for common tasks. Held by Bruno Morais. With them you perform routine tasks with fewer lines, writing less and doing much more.

[](#bmorais-code-is-a-set-of-small-and-optimized-php-components-for-common-tasks-held-by-bruno-morais-with-them-you-perform-routine-tasks-with-fewer-lines-writing-less-and-doing-much-more)

BMorais Code é um conjunto de pequenos e otimizados componentes PHP para tarefas comuns. Mantido por Bruno Morais. 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)

Database is available via Composer:

```
"bmorais/database": "2.0.*"
```

or run

```
composer require bmorais/database
```

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 Database, 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. 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)

```
const CONFIG_DATA_LAYER = [
    "driver" => "mysql",
    "host" => "localhost",
    "port" => "3306",
    "dbname" => "database",
    "username" => "user",
    "passwd" => "",
    "options" => [
        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8, lc_time_names = 'pt_BR'",
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
        PDO::ATTR_CASE => PDO::CASE_NATURAL,
        PDO::MYSQL_ATTR_FOUND_ROWS => true,
        PDO::ATTR_STRINGIFY_FETCHES => true
    ],
    "homologation" => "homologacao",
    "directory_models" => "App\\Models\\",
    "display_errors_details" => true,
];
```

#### your model

[](#your-model)

###### The Database 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-database-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 database é 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 CRUD.

```
