I have been using prepared insert statements for some years and assumed it was binding parameters properly or would give an error but it seems not as the following php binds and
I'm not an expert for sure, but at first look. You have:
$id1 = 'aaaaaaa';
$id2= 'aaaaaaa';
$result = $stmt->bind_param('ii', $id1, $id2);
Thing is your 'ii' parameter says that you will be binding integers! And in fact your $id1 and $id2 are strings. For strings you should go with:
$result = $stmt->bind_param('ss', $id1, $id2);