1. Go to this page and download the library: Download jonassilva/bmodel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jonassilva / bmodel example snippets
// Arquivo config.php
use Bmodel\Connection;
// Definir conexao com banco de dados
Connection::setConnection(
'banco', // Database
null, // Conexao ID
'localhost', // Hostname
NULL, // Port
'usuario', // Username
'senhaMuitoDificil' // password
);
Connection::setModelPath('Model'); // pasta
use Bmodel\Query;
$objCliente = Query::getTable('cliente')->find($id);
if (!$objCliente) {
throw new \Exception("Cliente não encontrado!", 404);
}
// Usar dados
echo $objCliente->id;
echo $objCliente->nome;
// $objCliente->toArray(); // como array associativo
// $objCliente->toArrayNum(); // como array (somente os valores)
// $objCliente->toJSON(); // como JSON
// Alterar:
$objCliente->nome = 'Joaquim';
$objCliente->save();
// Buscar por campo
// ... WHERE active = 1 AND email = '[email protected]' LIMIT 1
$objCliente = Query::getTable('cliente')->findBy([
'active' => '1',
'email' => '[email protected]'
]);
// Outras opcoes
// ... WHERE active = 1
// AND at_created > '2020-01-01 00:00:00'
// ORDER BY id DESC LIMIT 1
$objCliente = Query::getTable('cliente')
->where("active = 1")
->andWhere("at_created > '2020-01-01 00:00:00'")
->orderBy('id DESC')
->find();