mysql - Codeigniter batch insert query -
i try insert data in mysql table using codeigniter.
first retrieve columns config xml should insert data , targeted nodes should give xml insert values.
foreach ($sql_xml $children) { foreach ($children $index => $child) { if ($child != 'feed_id') { $keys[] = $index; $into[] = $child; //this holds table columns } } }
then retrieve multiple values per row want insert.
$products = array(); $data = array(); foreach ($target_xml $feeds) { $feeds = $this->xml2array($feeds); //simplexmlobject array $columns = new recursiveiteratoriterator(new recursivearrayiterator($feeds)); //get recursive iteration foreach ($columns $index=>$column) { if (in_array($index, $keys)) { //here values on matching nodes $data[] = $column; } } $products[] = $data;// datas should inserted }
here should come insert: have been looking in docs has quite workaround if inserted associative array in case created on flow on matching keys.
$this->db->insert_batch('mytable', $products);
the problem into
array contains target columns , don't know how push theme in product array.
i didn't understand example code correctly, here's try on it.
you want code
if ($child != 'feed_id') { $keys[] = $index; $into[] = $child; //this holds table columns }
to changed this
if ($child != 'feed_id') { $keys[$index] = $child; }
and want one
if (in_array($index, $keys)) { $data[] = $column; }
to change this
if ( array_key_exists($index, $keys) ) { $data[$keys[$index]] = $column; }
Comments
Post a Comment