phpBB

Development Wiki

Dbal.sql multi insert

From phpBB Development Wiki

dbal::sql_multi_insert –– Inserts multiple rows into a table.

Description

string dbal::sql_multi_insert ( string $table , array $sql_ary ] )

The $db->sql_multi_insert function is responsible for inserting multiple rows into a table easily and efficiently. This function automatically escapes strings and ensures type safety. When using the sql_multi_insert, there is no need to escape strings or force variable types. Although forcing variable types is still recommended as a general rule.

Parameters

table
Table to insert data into.

sql_ary
Multi-dimensional array holding the statement data.

Return Values

False if no statements were executed.

Examples

$sql_ary = array(
    
// One row
    
array(
        
'somedata'        => 'row 1',
        
'otherdata'        => 'otherdata 1',
        
'moredata'        => 'moredata 1'
    
),
    
// Anther row
    
array(
        
'somedata'        => 'row 2',
        
'otherdata'        => 'otherdata 2',
        
'moredata'        => 'moredata 2'
    
)
);

$db->sql_multi_insert(SOME_TABLE$sql_ary);

See Also