mysqli - php using prepared statement within foreach loop -
according example prepared statements first bind parameters , set values parameters. let's assume have 2-dim array $alias $array1 = [ 'id' => 1, 'tstamp' => 123456789, 'alias' => '$alias', ]; $array2 = [ 'id' => 1, 'tstamp' => 123456789, 'alias' => '$alias2', ]; $alias = [$array1, $array2]; why code working $insert = 'insert abcdef values (?,?,?)'; $insertstmt = $conn->prepare($insert); foreach ($alias $array) { $insertstmt->bind_param('iis', $array['id'], $array['tstamp'], $array['alias']); $insertstmt->execute(); } and not? $insert = 'insert abcdef values (?,?,?)'; $insertstmt = $conn->prepare($insert); $insertstmt->bind_param('iis', $array['id'], $array['tstamp'], $array['alias']); foreach ($alias $array) { $insertstmt->execute(); } if have bind...