v5:userguide:learn_bind:bind_vars
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| v5:userguide:learn_bind:bind_vars [2016/03/23 01:48] – mnewnham | v5:userguide:learn_bind:bind_vars [2016/03/23 02:04] (current) – mnewnham | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | <- ^ v5: | ||
| + | ~~NOTOC~~ | ||
| ====== Using Bind Variables ====== | ====== Using Bind Variables ====== | ||
| ===== Description ===== | ===== Description ===== | ||
| Line 27: | Line 29: | ||
| Note that the number of variable in the '' | Note that the number of variable in the '' | ||
| - | ===== Bind Placeholders Across Databases ===== | ||
| - | Bind placeholders vary from one database to another, so ADOdb provides a method [[v5: | ||
| - | <code php> | + | If an ADOdb method |
| - | $bindVars = array(' | + | |
| - | + | ||
| - | $col1Ph = $db-> | + | |
| - | $col2Ph = $db-> | + | |
| - | $col2Ph = $db-> | + | |
| - | + | ||
| - | $sql = " | + | |
| - | $result = $db-> | + | |
| - | </ | + | |
| - | + | ||
| - | In the above example, you can see that it is necessary to obtain a unique placeholder for each bind variable. This is because in some databases, the placeholder is uniquely associated with the column. So in the above example would appear as follows: | + | |
| - | ==== MySQL ==== | + | |
| - | SELECT * FROM some_table WHERE col1=? AND col2=? AND col3=? | + | |
| - | ==== Oracle ==== | + | |
| - | SELECT * FROM some_table WHERE col1=:col1 AND col2=:col2 AND col3=: | + | |
| - | ==== PostgreSQL ==== | + | |
| - | SELECT * FROM some_table WHERE col1=$1 AND col2=$2 AND col3=$3 | + | |
| - | + | ||
| - | ===== Databases Without Bind Support ===== | + | |
| - | You can still use the bind form of execute in ADOdb if the database | + | |
| - | + | ||
| - | + | ||
| - | ===== Bulk Binding ===== | + | |
| - | Some databases, Oracle | + | |
| - | + | ||
| - | ==== Concept ==== | + | |
| - | Using our previous example, let us assume that we need to insert multiple '' | + | |
| - | + | ||
| - | Traditionally, | + | |
| - | + | ||
| - | <code php> | + | |
| - | + | ||
| - | $sql = " | + | |
| - | $db-> | + | |
| - | $sql = " | + | |
| - | $db-> | + | |
| - | $sql = " | + | |
| - | $db-> | + | |
| - | $sql = " | + | |
| - | $db-> | + | |
| - | etc...... | + | |
| - | </ | + | |
| - | + | ||
| - | We can also use bind variables like this, in this case we may obtain speed improvements over the previous execution: | + | |
| - | + | ||
| - | <code php> | + | |
| - | $bindVars = array(' | + | |
| - | $sql = " | + | |
| - | $db-> | + | |
| - | $bindVars = array(' | + | |
| - | $sql = " | + | |
| - | $db-> | + | |
| - | etc...... | + | |
| - | </ | + | |
| - | + | ||
| - | If we now turn our '' | + | |
| - | + | ||
| - | <code php> | + | |
| - | $bindVars = array(array(' | + | |
| - | array(' | + | |
| - | array(' | + | |
| - | array(' | + | |
| - | $sql = " | + | |
| - | $db-> | + | |
| - | </ | + | |
| - | ===== Portable Support ===== | + | |
| - | In databases without Bulk Binding support, ADOdb simply iterates through the $bindVars array, and executes them individually. | + | |
| - | + | ||
| - | ===== 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: | + | |
| - | + | ||
| - | <code php> | + | |
| - | include ' | + | |
| - | + | ||
| - | $db = newAdoConnection(' | + | |
| - | + | ||
| - | $db-> | + | |
| - | + | ||
| - | /* | + | |
| - | * Enable bulk binding | + | |
| - | */ | + | |
| - | $db-> | + | |
| - | </ | + | |
| + | <WRAP box 350px> | ||
| + | == Syntax == | ||
| + | mixed someMethod | ||
| + | ( | ||
| + | | ||
| + | | ||
| + | ) | ||
| + | </ | ||
| + | |||
v5/userguide/learn_bind/bind_vars.1458694085.txt.gz · Last modified: (external edit)
