Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

Why use bind_param() at all?

Just pass the array to execute()

$stmt->execute($arr);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda