How to prepare a query without a certain number of fields?

$str = ";
 foreach (array_keys($c) as $key) if (!in_array($key,$this -> fields)) $str .= $key." = '$c[$key]',";
 $t = "UPDATE game SET ".mb_substr($str,0,-1)." WHERE `id` = '".$c['id']."' AND `type` = '".$c['type']."' LIMIT 1";
 $this -> db -> pdo -> query($t);
July 9th 19 at 10:10
4 answers
July 9th 19 at 10:12
And more? What should happen then?
and what exactly is not clear? and so it is hard to explain)) - Zande commented on July 9th 19 at 10:15
: request which should get the email - bailee_Stant commented on July 9th 19 at 10:18
: Yes everything)) thanks, I already figured out - Zande commented on July 9th 19 at 10:21
July 9th 19 at 10:14
well, I collect two arrays: one with parameters, the second with values.
i.e. something like this:
$params = [':param_1', ':param_2'];
$binds = [':param_1'=>1, ':param_2'=>2];
$binds[':id'] = 777;
$sql = 'UPDATE `table` SET' . implode(', ', $params) . 'where `id`=:id';
and bindisi how? - Zande commented on July 9th 19 at 10:17
:

$stmt = $pdo->prepare($sql);
$stmt->execute($binds); - bailee_Stant commented on July 9th 19 at 10:20
July 9th 19 at 10:16
July 9th 19 at 10:18
thank you)) understand)
foreach ($this -> fields as $k) unset($c[$k]); //do not not updateable
 $columns_s = implode(',', array_keys($c));
 // Update our results
 $this -> db -> pdo -> prepare("UPDATE game SET $columns_s") -> execute(array_values($c));

Find more questions by tags PHP PDOPHP