$sql = sprintf(
'insert into $s ($s) values ($s)',
$table,
implode(', ', array_keys($parameters)),
':' . implode(', :', array_keys($parameters))
);
try {
$statement = $this->pdo->prepare($sql);
$statement->execute($parameters);
} catch (Exception $e) {
die($e->getMessage());
}
OTHER FILE:
$query->test('todos', [
'description' => $_POST['name'] . ' ' . $_POST['lastName'],
'completed' => isset($_POST['finished'])
]);
It's weird cause if I do it manually instead it works perfectly
$sql = "insert into $table (description, completed) values (:description, :completed)";
But when I use sprintf and implode it gives me an error saying "base table or view not found" Any ideas why?