-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example of IN statement #7
Comments
This is an excellent question, thank you! The problem is that PHP’s built-in PDO, which is used internally in this library, does not support arrays as parameters but only scalars such as strings and integers. Right now, the only workaround is that you create your custom placeholder, which is a sequence of $statusPlaceholder = '(' . \str_repeat('?,', \count($value) - 1) . '?)'; Then use that placeholder instead of the normal $myQuery = "SELECT userImage FROM candid WHERE id = ? AND status IN " . $statusPlaceholder;
$result = $this->db->exec(
$myQuery,
// ...
); It gets worse – you also have to adjust your array of parameters, because the entries of $myParameters = \array_merge(
[ $userid ],
$status
);
$result = $this->db->exec(
// ...
$myParameters
); This is really ugly, but unfortunately, it is necessary at the moment in order to have a correct and safe solution. We don’t actually want that annoying way of writing these queries, of course. So, in the future, we should patch support for array parameters directly into this library, using the workaround above internally so that you don’t have to do this manually. But for now, no such solution is available. Sorry! Does that help? |
Hey, Thanks for the workaround. I'll give it a try. Since PHP-DB was last updated over an year ago, Is there any update releasing anytime soon? Also, I was checking out the forks of this library, One of the users have created |
Thanks! This library is still maintained and there will definitely be updates in the future. Just can’t give you any specific schedule yet. Sorry! By the way, the last update has not been over a year ago, but nine months ago. This specific feature, We’d love to have something like a |
Ugh, it’s been a while. Let’s keep this open, because it is still planned in fact, and so we can track it. Thank you! |
Hi,
I have the following statement:
And
$status = array('active','idle');
I am unable to fetch results from database.
I even tried changing $status from array to variable:
$status = "'interview','pending'";
Can you please help?
Note: This is a question and not an issue.
The text was updated successfully, but these errors were encountered: