public function bulkInsertRecords($tablename, $parameters, $limit = 25)
    {
        if(empty($parameters))
            throw new DatabaseException('bulkInsertRecords: no parameters.');

        $count      = 0;
        $tcount     = 0;
        $totalcount = count($parameters);

        foreach ($parameters as $value) {

            if (!is_array($value))
                throw new DatabaseException('bulkInsertRecords requires an array of arrays');

            if ($count == 0) {
                $sql = "INSERT INTO  ".$tablename." ";
                $sql .= " (".implode(",", array_keys($value)).")\n VALUES\n ";
                $first = false;
            }

            $sql .= "(".implode(",", array_map(array($this, 'quote'), (array)$value))."),\n";

            ++$count;
            ++$tcount;

            if ($count == $limit || $tcount == $totalcount) {
                $sql = substr($sql, 0, -2);
                $this->write($sql);
                $count = 0;
            }
        }
    }
public function bulkInsertRecords($tablename, $parameters, $limit = 25)
    {
        if(empty($parameters))
            throw new DatabaseException('bulkInsertRecords: no parameters.');

        $count      = 0;
        $tcount     = 0;
        $totalcount = count($parameters);

        foreach ($parameters as $value) {

            if (!is_array($value))
                throw new DatabaseException('bulkInsertRecords requires an array of arrays');

            if ($count == 0) {
                $sql = "INSERT INTO  ".$tablename." ";
                $sql .= " (".implode(",", array_keys($value)).")\n VALUES\n ";
                $first = false;
            }

            $sql .= "(".implode(",", array_map(array($this, 'quote'), (array)$value))."),\n";

            ++$count;
            ++$tcount;

            if ($count == $limit || $tcount == $totalcount) {
                $sql = substr($sql, 0, -2);
                $this->write($sql);
                $count = 0;
            }
        }
    }
public function bulkInsertRecords ( $ tablename , $ parameters , $ limit = 25 ) { if ( empty ( $ parameters ) ) throw new DatabaseException ( 'bulkInsertRecords: no parameters.' ) ; $ count = 0 ; $ tcount = 0 ; $ totalcount = count ( $ parameters ) ; foreach ( $ parameters as $ value ) { if ( ! is_array ( $ value ) ) throw new DatabaseException ( 'bulkInsertRecords requires an array of arrays' ) ; if ( $ count == 0 ) { $ sql = "INSERT INTO  " . $ tablename . " " ; $ sql .= " (" . implode ( "," , array_keys ( $ value ) ) . ")\n VALUES\n " ; $ first = false ; } $ sql .= "(" . implode ( "," , array_map ( array ( $ this , 'quote' ) , ( array ) $ value ) ) . "),\n" ; ++ $ count ; ++ $ tcount ; if ( $ count == $ limit || $ tcount == $ totalcount ) { $ sql = substr ( $ sql , 0 , - 2 ) ; $ this -> write ( $ sql ) ; $ count = 0 ; } } }
Inserts multiple records utilizing less INSERT statements.

This function will execute as many statements as necessary to insert
all the data supplied by the array {@link $parameters} inserting {@link $limit}
records per statement.  {@link $limit} is useful for preventing max
query size errors.

@param string $tablename  Table to insert records
@param string $parameters An associative array of rows and columns to insert
similar to the results of {@link readAll()}
<code>
array(
0 => array( 'id' => '1', 'col1' => 'value'),
1 => array( 'id' => '2', 'col1' => 'value'),
...
)
</code>
@param int    $limit      The maximum number of records to insert on a
single statement, defaults to 25

@return int Number of inserted rows
@throws DatabaseException if tablename or parameters array is empty
Inserts multiple records utilizing less INSERT statements .