Answer the question
In order to leave comments, you need to log in
How to bind an array of strings in an IN SQLite PDO statement via execute?
There is a string obtained from a POST/GET variable of the form (text1,text2,text3,text4,text5). The number of values is not defined, but they are all text. How to bind them in execute ? that is, I can pass it as a string, but then IN will receive one string in theory. How to solve the issue?
$tags= $_POST['tags']; // тут (текст,текст,текст,текст)
$db = new PDO('sqlite: files.sqlite');
$query = $db->prepare("SELECT * FROM files WHERE tags IN (:tags)");
$query->execute(array(':tags' => explode(',',$tags)));
$tags= $_POST['tags']; // тут (текст,текст,текст,текст)
$db = new PDO('sqlite: files.sqlite');
$query = $db->prepare("SELECT * FROM files WHERE tags IN (:tags)");
$query->execute(array(':tags' => "'" . explode("', '",$tags) . "'"));
Answer the question
In order to leave comments, you need to log in
https://phpdelusions.net/pdo#in
Named placeholders are more of a hassle, so I highly recommend positional ones. Especially if there is only one placeholder in the request.
Well, I don’t understand the point of writing the unfortunate field name 4 times, when one is enough
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question