0
I’m trying to pass more than an id to search in my program but the search only brings an object with the data of the first id, query code in sql:
public static function listar_servidores_ids($id){
//LISTA SERVIDORES SELECIONADOS
$pdo = \Core\DB::getConnection();
$sql = 'SELECT * FROM servidores WHERE id IN (?)';
$stmt = $pdo->prepare($sql);
$stmt->bindValue(1, $id);
$stmt->execute();
return $stmt-> fetchAll(\PDO::FETCH_OBJ);
}
(When I pass through the ids to the inves of "?" in the query it occurs normally, but when I pass for example '1.2'instead of $id in the bindValue only returns that of the first id, same thing as when I pass the ids via url Example:"http://localhost:8080/index? id/[1,4,3]") Controller code that receives the id and calls the query function in the database:
public function execute()
{
//CHAMA A OPERAÇÃO DE ALTERAR OS DADOS UM SERVIDOR
$ids = Input::args('id');
$ids = str_ireplace("[", "", $ids);
$ids = str_ireplace("]", "", $ids);
$this->set( 'servidor', \App\Operacoes::listar_servidores_ids( $ids ) );
}
u do not bind an array on top of a single query. You need to do something like: Dynamic bind with prepare
– rray