Bind Param with Array - PHP and MySQLi

3

I have the code:

<?php

$clientes = implode(', ', $clientes);

$busca = $mysqli->prepare("SELECT nome FROM clientes WHERE id IN (?)");
$busca->bind_param("s", $clientes);
$busca->execute();
$busca->bind_result($nome);
$busca->store_result();

if($busca_num_rows() > 0){

   while($busca->fetch()){
    
        echo $nome . "<br>";

   }

}

?>

Remembering that the variable $clientes is an array that takes the following values

  

2, 15, 78, 93

That is, I want to retrieve the names of the clients with the above id's.

My code even works, however it only returns me a client (the client with id 2).

Remembering that I tried the following way and it worked:

$busca = $mysqli->prepare("SELECT nome FROM clientes WHERE id IN ($clientes)");

I do not want to concatenate the variable inside the query.

How to proceed in this case?

    
asked by anonymous 07.05.2018 / 14:05

0 answers