I'm trying to do a multiple insert on a mysql table using prepared statements but it is not working as expected.
I do not get any error message.
I only get the first result into the table.
This is the relevant code
$array_of_data // contains all the information that I want to insert, I'm sure it's there.
$table = 'table_name';
$query = "INSERT INTO ".$table."( `some_id`, `name`, `last_name_1`, `last_name_2` ) VALUES ( ?, ?, ?, ? )";
$connection = conexion_mysql();
$init = mysqli_stmt_init( $connection );
$prepare = mysqli_stmt_prepare( $init, $query );
foreach ( $array_of_data as $keys => $values ) {
$bind = mysqli_stmt_bind_param( $init, 'ssss', $values['some_id'], $values['name'], $values['last_name_1'], $values['last_name_2'] );
$execute = mysqli_stmt_execute( $init );
}
unset( $keys, $values );
$close = mysqli_stmt_close( $init );
mysqli_close( $connection );
I have checked some other answers here and over the Internet but it seems that I'm still doing something wrong
The system I'm workning on has
- PHP 5.4.16 (yes I should upgradde that but I can't) MySQL
- 5.5.56-MariaDB (can't change it either but it's not too bad)