"how use an array/implode in the select query pdo" Code Answer

1

change:

$stmt = $pdo->prepare("select :fields from `users` where `user_id` = :user_id");

to:

$stmt = $pdo->prepare("select $fields from `users` where `user_id` = :user_id");

and remove $fields from the execute parameter array.

parameterized placeholders are only for values.

update

also this line is wrong:

$fields = '`' . implode(', ', $func_get_args) . '`';

this will output a ` outside the the field list rather than each column name.

try removing them like this:

$fields = implode(', ', $func_get_args);
By Morez on April 27 2022

Answers related to “how use an array/implode in the select query pdo”

Only authorized users can answer the Search term. Please sign in first, or register a free account.