Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
How to add special condition to bind_param?

I have an array with topics and which I generate attributes to add to the query and to the bind_param:

   $arr = explode(',', $theme);
   $strMarcas  = str_repeat('?,', count($arr) - 1) . '?';
   $strTipos = str_repeat('s', count($arr));

For example usage:

   WHERE main_cover in ($strMarcas)

And in the bind_param:

   $stmt->bind_param($strTipos, ...$arr);

Now the problem is that I need to pass other conditions to the WHERE example:

   WHERE main_cover in ($strMarcas) AND language=? AND active=?

And, I don't know how to pass the conditions, I already tried this:

   $stmt->bind_param($strTipos . "si", ...$arr, $language, $active);

And, that generates this error:

Fatal error: Cannot use positional argument after argument unpacking

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Can you do something like this?

Instead of:

$stmt->bind_param($strTipos . "si", ...$arr, $language, $active);

which errors with:

Fatal error: Cannot use positional argument after argument unpacking

Can you append to the array before you try to bind it?

$ar[] = $language;
$ar[] = $active;
$stmt->bind_param($strTipos . "si", ...$arr);

If that doesn't work, can you make a temporary array by looping through the values, then append the last 2, then bind the temporary array instead?

over 4 years ago · Santiago Trujillo Relatório

0

Why use bind_param() at all?

Just pass the array to execute()

$stmt->execute($arr);
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda