robsonvleite / datalayer

The data layer is a persistent abstraction component of your database that PDO (O data layer é um componente para abstração de persistência no seu banco de dados que usa PDO com prepared statements)
https://www.upinside.com.br
MIT License
144 stars 53 forks source link

AND Clause #9

Closed peixespnsc closed 4 years ago

peixespnsc commented 4 years ago

Is there AND clause implemented? If so, how to proced? Thanks!

omnispecies commented 4 years ago

I've found the solution, it's like so:

//find one user by two conditions

$user = $model->find("first_name = :name AND last_name = :last", "name=Robson&last=Leite")->fetch();

echo $user->first_name . " " . $user->first_last;

But now I have a problem with IN, the "find" only returns the first value

//find users by two conditions

$user = $model->find("first_name = :name AND id IN (:id)", "name=Robson&id=1,2,3,4")->fetch(true);

var_dump($user);
rodineiti commented 4 years ago

Boa tarde galera, vejam meu pull request que resolvo todos estes problemas.

https://github.com/rodineiti/datalayer/blob/develop/README.md

16

thiagocmelo commented 4 years ago

Rodinei, estou tomando erro Undefined method 'where'. ao tentar usar a forma where da nova consulta implementada.

$funcionario = new Funcionario(); $listFunc = $funcionario->where("id", ">", 1)->find()->fetch(true);

rodineiti commented 4 years ago

Rodinei, estou tomando erro Método indefinido 'where'. ao tentar usar uma forma em que a nova consulta é implementada.

$funcionario = new Funcionario(); $listFunc = $funcionario->where("id", ">", 1)->find()->fetch(true);

Bom dia Thiago, obrigado por utilizar. Segue nova forma de utilizar com o método Where:

<?php

$funcionario = new Funcionario();
$listFunc = $funcionario->where("id", ">", 1)->get(true)

No método get(), eu já chamo o find e o fetch, desta forma, as condições utilizadas são a da where. Ainda assim, com os novos recursos que fiz, mantive a retro-compatibilidade dos métodos atuais como find. Dá uma olhada nos arquivos de exemplo: https://github.com/rodineiti/datalayer/tree/develop/example

Lá eu mostro como utilizar. Mas pode contar comigo se precisar de ajuda.

image

robsonvleite commented 4 years ago
$users = $model->find("age > :age", "age=16")->fetch();
$user = $model->find("first_name = :name AND last_name = :last", "name=Robson&last=Leite")->fetch();