cyrill@malevanov.spb.ru
I've created patch to make possible use :param style
parameters in MySQL/PostgreSQL/other.
Replace code from line 798 in adodb.inc.php with
if (!$array_2d) $inputarr = array($inputarr);
foreach($inputarr as $arr) {
$sql = ''; $i = 0;
foreach($arr as $k => $v) {
// not try to add if params are made with :param
if ($i < count($sqlarr))
$sql .= $sqlarr[$i];
// from Ron Baldwin <ron.baldwin#sourceprose.com>
// Only quote string types
$typ = gettype($v);
if ($typ == 'string')
$arr[$k] = $this->qstr($v);
else if ($typ == 'double')
$arr[$k] = str_replace(',','.',$v); // locales fix so
1.1 does not get converted to 1,1
else if ($v === null)
$arr[$k] = 'NULL';
if (count($sqlarr) != 1)
$sql .= $arr[$k];
$i += 1;
}
if (isset($sqlarr[$i])) {
$sql .= $sqlarr[$i];
if ($i+1 != sizeof($sqlarr)) ADOConnection::outp(
"Input Array does not match ?: ".htmlspecialchars($sql));
} else if ($i != sizeof($sqlarr))
ADOConnection::outp( "Input array does not match ?:
".htmlspecialchars($sql));
// dirty hack - to make :param work in PostgreSQL
$sql = preg_replace('/:(\w+)( |$|\+|\-|\/|\*)/e',
"\$arr['$1'].'$2'", $sql);
$ret =& $this->_Execute($sql);
if (!$ret) return $ret;
}
And you could use
Execute("select * from table where a=:a and b=:b",
array('a'=>12, 'b'=>'abcdef'));
with PostgreSQL.
DIFF file for ADODB 4.60 adodb.inc.php