[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/db/ -> sql_insert_buffer.php (summary)

This file is part of the phpBB Forum Software package.

Copyright: (c) phpBB Limited
License: GNU General Public License, version 2 (GPL-2.0)
File Size: 146 lines (4 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

sql_insert_buffer:: (4 methods):
  __construct()
  insert()
  insert_all()
  flush()


Class: sql_insert_buffer  - X-Ref

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->sql_multi_insert() include:

- Going over max packet size of the database connection is usually prevented
because the data is submitted in batches.

- Reaching database connection timeout is usually prevented because
submission of batches talks to the database every now and then.

- Usage of less PHP memory because data no longer needed is discarded on
buffer flush.

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:
<code>
$buffer = new \phpbb\db\sql_insert_buffer($db, 'test_table', 1234);

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

$buffer->flush();
</code>
__construct(\phpbb\db\driver\driver_interface $db, $table_name, $max_buffered_rows = 500)   X-Ref

param: \phpbb\db\driver\driver_interface $db
param: string          $table_name
param: int             $max_buffered_rows

insert(array $row)   X-Ref
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 $max_buffered_rows.

param: array $row
return: bool        True when some data was flushed to the database.

insert_all(array $rows)   X-Ref
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 count($rows) should be kept
small.

param: array $rows
return: bool        True when some data was flushed to the database.

flush()   X-Ref
Flushes the buffer content to the DB and clears the buffer.

return: bool        True when some data was flushed to the database.



Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1