I need to select some rows from a database using a statement IN. I want to do this using a prepared statement. This is my code:
<?php
$lastnames = array('braun', 'piorkowski', 'mason', 'nash');
$in_statement = '"' . implode('", "', $lastnames) . '"';
$data_res = $_DB->prepare('SELECT `id`, `name`, `age` FROM `users` WHERE `lastname` IN (?)');
$data_res->bind_param('s', $in_statement);
$data_res->execute();
$result = $data_res->get_result();
while ($data = $result->fetch_array(MYSQLI_ASSOC)) {
...
}
?>
But it returns nothing, although all the data exists in the database.
And one more thing: if I pass $in_statementdirectly to fulfill the request and execute it, the data will be returned. Therefore, the problem arises in preparation.
I searched the question on Google, but it was not "successful." What is wrong with my code?
Thanks for the help!
source
share