bmorais / database
The data layer is a persistent abstraction component of your database that PDO
Requires
- php: >=7.4
- ext-json: *
- ext-mbstring: *
- ext-pdo: *
Requires (Dev)
- rector/rector: ^0.19.2
- dev-main
- v1.0.86
- v1.0.85
- v1.0.84
- v1.0.83
- v1.0.82
- v1.0.81
- v1.0.80
- v1.0.79
- v1.0.78
- v1.0.77
- v1.0.76
- v1.0.75
- v1.0.74
- v1.0.73
- v1.0.72
- v1.0.71
- v1.0.70
- v1.0.69
- v1.0.68
- v1.0.67
- v1.0.66
- v1.0.65
- v1.0.64
- v1.0.63
- v1.0.62
- v1.0.61
- v1.0.60
- v1.0.59
- v1.0.58
- v1.0.57
- v1.0.56
- v1.0.55
- v1.0.53
- v1.0.52
- v1.0.51
- v1.0.50
- v1.0.49
- 1.0.48
- 1.0.47
- 1.0.46
- 1.0.45
- 1.0.44
- 1.0.43
- 1.0.42
- 1.0.41
- 1.0.40
- 1.0.39
- 1.0.38
- 1.0.37
- 1.0.36
- 1.0.35
- 1.0.34
- 1.0.33
- 1.0.32
- 1.0.31
- v1.0.30
- v1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-extractModel
- dev-add-license-1
This package is auto-updated.
Last update: 2024-10-28 18:31:45 UTC
README
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
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
- 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
Database is available via Composer:
"bmorais/database": "1.0.*"
or run
composer require bmorais/database
Documentation
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
To begin using the Data Layer, you need to connect to the database (MariaDB / MySql). For more connections PDO connections manual on PHP.net
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
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
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.
<?php class Usuario extends Crud { public function __construct() { $this->database = "nomeBD"; $this->tableName = "USUARIO"; $this->classModel = "AutUserModel"; } /** * @param $codusuario * @return array|null */ public function buscarIdObj($codusuario) { $result = $this->select("*","WHERE CODUSUARIO=?",[$codusuario]); if ($result){ return $result; } else { return null; } } /** * @param $codusuario * @return AutUserModel[] | null */ public function buscarIdModelExample($codusuario) { $result = $this->select("*","WHERE CODUSUARIO=?",[$codusuario], true); if ($result){ return $result; } else { return null; } } /** * @param $codusuario * @return AutUserModel[] | null */ public function buscarIdModelExample2($codusuario) { $sql = "SELECT * FROM AUT_USER AS U WHERE U.CODUSUARIO=?"; $params = array($codusuario); $result = $this->executeSQL($sql,$params); if (!empty($result)){ return $this->getObjModel($result,$this->classModel); } else { return null; } } /** * @param $coduser * @return bool */ public function updateUser($name, $email, $coduser) { $result = $this->update("NAME, EMAIL", array($name, $email), "CODUSER=?"); if ($result){ return true; } else { return false; } } /** * @param $name * @return bool */ public function insertUser($name, $email) { $result = $this->insert("NOME, EMAIL", array($name, $email)); if ($result){ return true; } else { return false; } } }
Contributing
Please see CONTRIBUTING for details.
Support
Security: If you discover any security related issues, please email contato@bmorais.com instead of using the issue tracker.
Se você descobrir algum problema relacionado à segurança, envie um e-mail para contato@bmorais.com em vez de usar o rastreador de problemas.
Thank you
Credits
- Bruno Morais (Developer)
- Athus Felipe (Developer)
Contributing
🚧 Contributing Guidelines - Currently being updated 🚧
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the appropriate tag. Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Remember to include a tag, and to follow Conventional Commits and Semantic Versioning when uploading your commit and/or creating the issue.
Aknowledgements
Thank you to all the people who contributed to this project, whithout you this project would not be here today.
Obrigado a todas as pessoas que contribuíram para este projeto, sem vocês este projeto não estaria aqui hoje.
License
The MIT License (MIT). Please see License File for more information.