Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
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 answers
Answer question

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 Report

0

Why use bind_param() at all?

Just pass the array to execute()

$stmt->execute($arr);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!