KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Right now I need to use the following structure to cope with binding multiple parameters into a mysqli query: if ($words_total == 1) { $statement -> bind_param("s", $words[0]); } else if ($words_total == 2) { $statement -> bind_param("ss", $words[0], $words[1]); } else if ($words_total == 3) { $statement -> bind_param("sss", $words[0], $words[1], $words[2]); } //and so on.... I work out the number of question marks using the code below and insert it into my query: $marks = ""; for($i = 1; $i<=$words_total; $i++) { if ($i == $words_total) { $marks .= "?"; } else { $marks .= "?,"; } } My question is surely there must be a way of handling as many inputs into the query as I need dynamically. Hardcoding the bind_param() seems like a really bad way of handling this. I am using php version 5.4.10
Tags (comma-separated)
Save Edits
Cancel