ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:learn_bind:portability

This is an old revision of the document!


Bind Placeholders Across Databases

Bind placeholders vary from one database to another, so ADOdb provides a method param() that returns a database specific placeholder. Using the above example, we can write it as a portable statement:

$bindVars = array('A','B','C');
 
$col1Ph = $db->param('col1');
$col2Ph = $db->param('col2');
$col3Ph = $db->param('col3');
 
$sql = "SELECT * FROM some_table 
                WHERE col1=$col1Ph 
                  AND col2=$col2ph 
                  AND col3=$col3Ph";
$result = $db->execute($sql,$bindVars);

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=: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 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/portability.1458695240.txt.gz · Last modified: 2017/04/21 11:40 (external edit)