insert big array into database $array = Array(
  [a001] =&gt; Array(
    [0] =&gt; Array(
      [id] =&gt; 1789823
      [start] =&gt; 2014-09-29
      [end] =&gt; 2014-10-02
      [status] =&gt; 1
    )
  )
)


function to insert reservation:

    foreach ($array as $room_id =&gt; $item) {
      foreach ($item as $reservation) {
        db_insert('reservation')-&gt;fields(
          array(
            'room_id' =&gt; $room_id, 
            'id' =&gt; $reservation['id'],
            'start' =&gt; $reservation['start'],
            'end' =&gt; $reservation['end'],
            'status' =&gt; $reservation['status']
          )
        )-&gt;execute;
      }
    }


I have an multidimensional array $array and it has about 30000 records of $reservation index. Using looping method above in my personal computer, it takes about 30 minutes to insert all of reservation, my PC spec is (dual core, memory 2GB).

Is any better implementation to do insert job?
You should avoid executing insert many times. It is enough to call -&gt;fields multiple times, like this:

$query = db_insert('reservation');
foreach ($array as $room_id =&gt; $item) {
  foreach ($item as $reservation) {
    $query-&gt;fields(
      array(
        'room_id' =&gt; $room_id, 
        'id' =&gt; $reservation['id'],
        'start' =&gt; $reservation['start'],
        'end' =&gt; $reservation['end'],
        'status' =&gt; $reservation['status']
      )
    );
  }
}
$query-&gt;execute();


This will speed up things, allowing database to prepare space for new data in one step, but with 30 thousands of records it still may take time. Be sure to tune your database accordingly - but that's out of the scope of Drupal Answers.

If you can't optimize DB enough, consider using Batch API for the job. It will make things a bit slower than the code above, but by importing a hundred or two each step you will avoid HTTP connection timeouts, PHP timeouts etc. Just make sure you only execute once per step with hundred records - even with Batch API it is good approach to group rows in as few inserts as practical.