Database Abstraction Layer for PHP

User Tools

Site Tools


Bulk Binding

Some databases, Oracle in particular, offer massive performance improvements in insertion performance when used with 2 dimensional bind arrays. This technique is known as Bulk Binding.


Using our previous example, let us assume that we need to insert multiple some_table records, and that we can determine the values to be inserted prior to the execution of all the statements

Enabling Bulk Bind Support

Bulk Binding using 2D arrays is disabled by default in ADOdb. It must be deliberately enabled in the driver using the following syntax:

include 'adodb/';
$db = newAdoConnection('drivername');
* Enable bulk binding
$db->bulkBind = true;

Code Modifications

Traditionally, we might write our insert statement like this:

$sql = "INSERT INTO some_table(col1,col2,col3) values ('A','B','C')";
$sql = "INSERT INTO some_table(col1,col2,col3) values ('D','E','F')";
$sql = "INSERT INTO some_table(col1,col2,col3) values ('G','H','I')";
$sql = "INSERT INTO some_table(col1,col2,col3) values ('J','K','L')";

We can also use bind variables like this, in this case we may obtain speed improvements over the previous execution:

$bindVars = array('A','B','C');
$sql = "INSERT INTO some_table(col1,col2,col3) values (?,?,?)";
$bindVars = array('D','E','F');
$sql = "INSERT INTO some_table(col1,col2,col3) values (?,?,?)";

If we now turn our $bindVars into a 2 dimensional array, we can create multiple records using a single SQL statement:

$bindVars = array(array('A','B','C'),
$sql = "INSERT INTO some_table(col1,col2,col3) values (?,?,?)";

Portable Support

In databases without Bulk Binding support, ADOdb simply iterates through the $bindVars array, and executes the prepared statement individually.

End Of Tutorial

v5/userguide/learn_bind/bulkbinding.txt · Last modified: 2016/03/23 02:09 by mnewnham