Alex Rivera | Logout

How to insert multiple rows from array using CodeIgniter framework?

Asked 2009-04-23T01:39:06.257
137

I'm passing a large dataset into a MySQL table via PHP using insert commands and I'm wondering if it's possible to insert approximately 1000 rows at a time via a query other than appending each value on the end of a mile-long string and then executing it. I am using the CodeIgniter framework so its functions are also available to me.

Edit
Report

1 Answer

2
$query= array(); 
foreach( $your_data as $row ) {
    $query[] = '("'.mysql_real_escape_string($row['text']).'", '.$row['category_id'].')';
}
mysql_query('INSERT INTO table (text, category) VALUES '.implode(',', $query));
answered 2013-07-20T11:28:02.247

Your Answer