tags:

views:

185

answers:

1

what would be the efficient way of saving the following array using php (cakephp)? each value needs to go into a new row in the table?

Array
(
    [0] => 6786754654
    [1] => 5643564545
    [2] => 344544545
    [3] => 233245654654
    [4] => 453454654654
    [5] => 6546542323
    [6] => 654654654
    [7] => 645654654
    etc....
)

thanks

+4  A: 

2 choices:

  1. Format the array as required by Model::saveAll()
  2. Loop through the array calling Model::create(), then Model:save()

I'd recommend option 1 as you can use Model::saveAll($data, array('validate' => 'first')); to ensure that all values are valid before saving any of them.

neilcrookes
that is good idea.
ondrobaco