D
D
Dreaded2018-05-20 12:39:04
PHP
Dreaded, 2018-05-20 12:39:04

How to insert data from an array into a prepared expression?

I have a number of id's stored in an array. Each time the data in the array is updated.
The task is to form a query in the database in such a way that all IDs are passed in one query. The question is how to substitute data from an array into a prepared expression?
This is how I am trying to do it, but the query only returns 1 row.

$ids = array(1,2,3,4,5,6);
    $strIds = implode(',', $ids);
    $query = "SELECT * FROM table WHERE id IN (?)";
    $stmt = mysqli_prepare($connection , $query);
    mysqli_stmt_bind_param($stmt, 's', $strIds);
    mysqli_stmt_execute($stmt);
    $response = mysqli_fetch_all(mysqli_stmt_get_result($stmt));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2018-05-20
@Dreaded

https://websitebeaver.com/prepared-statements-in-p...
a better to use pdo.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question