1. Go to this page and download the library: Download patrick-barreto/data-base 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/ */
patrick-barreto / data-base example snippets
DotEnv\DotEnv::fill(PATH_.ENV_FILE);
//Model
class Users extends DataBaseCorrespondence {
private static string $table = 'users';
public static function getTable(){
return self::$table;
}
public function getProperty($property){
return $this->$property;
}
}
//Repository
class UserRepository extends Repository{
public function findUsers() {
return $this->select()->setFields(['id', 'name', 'email', 'phone'])
->fetchObject(false, $this->getDtoPath());
}
}
//Using in Controller for exemple
class Users {
use UserRepository;
use Users;
public function findUsers() {
//This will be and instance of UserRepository, class responsable to provide methods of User Object.
$usersRepository = new UserRepository(new Users);
//This will return an instance of Users.
$users = $usersRepository->findUsers();
}
}
namespace Your\NameSpace
use DataBase\Crud;
$homens = new Crud('homens');
$mulheres = new Crud('mulheres');
$animais = new Crud('animais');
$homens->insert->setFields(['name'])->setValues([["Pedro"],["João"],["Paulo"]])->runQuery();
$mulheres->insert->setFields(['name'])->setValues([["Maria"],["Ana"],["Marcia"]])->runQuery();
$animais->insert->setFields(['name'])->setValues([["Gato"],["Cachorro"],["Papagaio"]])->runQuery();
$mulheres->select->setFields(['homens.name as homemName, mulheres.name as mulherName'])
->setInnerJoin(['table' => 'homens'], ['table' => 'mulheres'] )
->setWhere('homens.name = "João"');
namespace Your\NameSpace
use DataBase\Actions\DML\Commands\Select;
$select = new Select;
$select->setTable('tableName');
$select->setWhereIn('nome', ['pedro', 'joão', 'josé']);
$select->fetchAssoc(true);
namespace Your\NameSpace
use DataBase\Query;
$sql = "SELECT * FROM teste";
$query = new Query;
$result = $query->runQuery($sql)->fetchAll(PDO::FETCH_ASSOC);
public function getTableName()
public function setTable(string $tableName)
public function setWhere(string $condition)
public function setWhereIn(string $column, array $options)
public function setInnerJoin(array $joinedTable, array $newTableJoin)
public function setRightJoin(array $joinedTable, array $newTableJoin)
public function setLeftJoin(array $joinedTable, array $newTableJoin)
public function setFullJoin(array $newTableJoin)
public function setCrossJoin(array $newTableJoin)
public function setDistinct(bool $requiereDistinct)
public function setFields(array $fields)
public function setLimit(int $limit, int $offset = 0)
public function setOrder(string $fields, string $order = "ASC")
public function setGroupBy(array $fields)
public function setHaving(string $condition)
public function buildQuery(bool $subquery = false)
public function fetchAssoc(bool $returnAll = false)
public function fetchObject(bool $returnAll = false, string $class = stdClass::class)
public function setIgnore(bool $requiereIgnore)
public function setFields(array $fields)
public function setValues(array $values)
public function setInsertSelect(string $query)
public function buildQuery()
public function runQuery()
public function setSet(array $columnValue)
public function buildQuery()
public function runQuery()
public function buildQuery()
public function runQuery()
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.