PHP Class Piwik\Db\BatchInsert

Show file Open project: piwik/piwik Class Usage Examples

Public Methods

Method Description
createTableFromCSVFile ( string $tableName, array $fields, string $filePath, array $fileSpec ) : boolean Batch insert into table from CSV (or other delimited) file.
tableInsertBatch ( string $tableName, array $fields, array $values, boolean $throwException = false, string $charset = 'utf8' ) : boolean Performs a batch insert into a specific table using either LOAD DATA INFILE or plain INSERTs, as a fallback. On MySQL, LOAD DATA INFILE is 20x faster than a series of plain INSERTs.
tableInsertBatchIterate ( string $tableName, array $fields, array $values, boolean $ignoreWhenDuplicate = true ) Performs a batch insert into a specific table by iterating through the data

Protected Methods

Method Description
createCSVFile ( string $filePath, array $fileSpec, array $rows ) Create CSV (or other delimited) files

Private Methods

Method Description
getBestPathForLoadData ( )

Method Details

createCSVFile() protected static method

Create CSV (or other delimited) files
protected static createCSVFile ( string $filePath, array $fileSpec, array $rows )
$filePath string filename to create
$fileSpec array File specifications (delimiter, line terminator, etc)
$rows array Array of array corresponding to rows of values

createTableFromCSVFile() public static method

Batch insert into table from CSV (or other delimited) file.
public static createTableFromCSVFile ( string $tableName, array $fields, string $filePath, array $fileSpec ) : boolean
$tableName string Name of table
$fields array Field names
$filePath string Path name of a file.
$fileSpec array File specifications (delimiter, line terminator, etc)
return boolean True if successful; false otherwise

tableInsertBatch() public static method

Performs a batch insert into a specific table using either LOAD DATA INFILE or plain INSERTs, as a fallback. On MySQL, LOAD DATA INFILE is 20x faster than a series of plain INSERTs.
public static tableInsertBatch ( string $tableName, array $fields, array $values, boolean $throwException = false, string $charset = 'utf8' ) : boolean
$tableName string PREFIXED table name! you must call Common::prefixTable() before passing the table name
$fields array array of unquoted field names
$values array array of data to be inserted
$throwException boolean Whether to throw an exception that was caught while trying LOAD DATA INFILE, or not.
$charset string The charset to use, defaults to utf8
return boolean True if the bulk LOAD was used, false if we fallback to plain INSERTs

tableInsertBatchIterate() public static method

NOTE: you should use tableInsertBatch() which will fallback to this function if LOAD DATA INFILE not available
public static tableInsertBatchIterate ( string $tableName, array $fields, array $values, boolean $ignoreWhenDuplicate = true )
$tableName string PREFIXED table name! you must call Common::prefixTable() before passing the table name
$fields array array of unquoted field names
$values array array of data to be inserted
$ignoreWhenDuplicate boolean Ignore new rows that contain unique key values that duplicate old rows