phpBB API Documentation
Class

phpbb\db\sql_insert_buffer

class sql_insert_buffer

Collects rows for insert into a database until the buffer size is reached.

Then flushes the buffer to the database and starts over again.

Benefits over collecting a (possibly huge) insert array and then using $db->sqlmultiinsert() include:

Attention: Please note that users of this class have to call flush() to flush the remaining rows to the database after their batch insert operation is finished.

Usage: $buffer = new \phpbb\db\sqlinsertbuffer($db, 'test_table', 1234);

while (do_stuff())
{
    $buffer->insert(array(
        'column1' => 'value1',
        'column2' => 'value2',
    ));
}

$buffer->flush();

Methods

__construct(driver_interface $db, string $table_name, int $max_buffered_rows = 500)

bool insert(array $row)

Inserts a single row into the buffer if multi insert is supported by the database (otherwise an insert query is sent immediately).

bool insert_all(array $rows)

Inserts a row set, i.e.

bool flush()

Flushes the buffer content to the DB and clears the buffer.

Details

at line 71
public __construct(driver_interface $db, string $table_name, int $max_buffered_rows = 500)

Parameters

driver_interface $db
string $table_name
int $max_buffered_rows

at line 89
public bool insert(array $row)

Inserts a single row into the buffer if multi insert is supported by the database (otherwise an insert query is sent immediately).

Then flushes the buffer if the number of rows in the buffer is now greater than or equal to $maxbufferedrows.

Parameters

array $row

Return Value

bool True when some data was flushed to the database. False otherwise.

at line 115
public bool insert_all(array $rows)

Inserts a row set, i.e.

an array of rows, by calling insert().

Please note that it is in most cases better to use insert() instead of first building a huge rowset. Or at least sizeof($rows) should be kept small.

Parameters

array $rows

Return Value

bool True when some data was flushed to the database. False otherwise.

at line 134
public bool flush()

Flushes the buffer content to the DB and clears the buffer.

Return Value

bool True when some data was flushed to the database. False otherwise.