how can insert variable to a prepared PDO statement? I don't know which column will be modified.
the code is (throws error):
private function deleteData($column, $id)
{
$stmt = $this->db->prepare('UPDATE table SET $column = "" WHERE id = ?'); // $column variable has 1 out of 4 values, and it changes dynamically
$stmt->bind_param('i', $id);
$stmt->execute();
}
Error: Fatal error: Uncaught mysqli_sql_exception: Unknown column '$column' in 'field list' in
as I understood from the topic linked the only option is to make a switch?
switch ($column)
{
case 'column1':
$stmt = $this->db->prepare('UPDATE table SET column1 = "" WHERE id = ?');
break;
case 'column2':
$stmt = $this->db->prepare('UPDATE table SET column2 = "" WHERE id = ?');
break;
and so on...