v5:userguide:learn_bind:bind_vars
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
v5:userguide:learn_bind:bind_vars [2016/03/23 01:20] – created 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 ===== | ||
- | Using //**bind variables**// | + | Using //**bind variables**// |
+ | |||
+ | In addition, there may be performance improvements in statements executed multiple times. | ||
===== Bind Variables In ADOdb ===== | ===== Bind Variables In ADOdb ===== | ||
Line 12: | Line 16: | ||
* Statement without Binding | * Statement without Binding | ||
*/ | */ | ||
- | $sql = 'SELECT * FROM table WHERE col1=' | + | $sql = "SELECT * FROM some_table |
$result = $db-> | $result = $db-> | ||
Line 19: | Line 23: | ||
*/ | */ | ||
$bindVars = array(' | $bindVars = array(' | ||
- | $sql = 'SELECT * FROM table WHERE col1=? AND col2=? AND col3=?"; | + | $sql = "SELECT * FROM some_table |
$result = $db-> | $result = $db-> | ||
</ | </ | ||
Line 25: | 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 does support binding, the syntax definition in the documentation will appear similar to this: |
- | $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 database. So in the above example would appear as follows: | + | <WRAP box 350px> |
- | ==== MySQL ==== | + | == Syntax |
- | | + | |
- | ==== Oracle ==== | + | |
- | | + | string $sqlStatement, |
- | ==== PostgreSQL ==== | + | optional mixed $bindVars |
- | | + | |
- | + | </ | |
- | ===== Databases Without Bind Support ===== | + | |
- | You can still use the bind form of execute in ADOdb if the database does not support binding. In this case ADOdb simply rewrites the query statement for you back into the non-bind form. | + | |
v5/userguide/learn_bind/bind_vars.1458692455.txt.gz · Last modified: (external edit)