Subject Re: [firebird-php] Variable parameters number
Author masotti
Hi Lester,
thank you for answer to my question.
You gave me to think about the problem, and I must admit that I master
Delphi Win32 but don't master PHP...
Now I solved, don't know how tricky is the solution, but report here
anyway, if someone interested or has better ideas... wellcome!

Having a almost generic string query where parameters are nominative and
univocally determined by a regular expression (like BDE usual
:PARAMETER_NAME), and having an associative array like:
$arr['ParameterName'] = $value;
I create a new query string with '?' instead of params and a new array
with associated values: so I have same parameter value to same name.
The function is simplified in the connection and transaction
start/commit code.

function exec_qry_params ( $qry, $arr )
{
$regs = array();
$pat1 = '/:([a-z][_$0-9a-z]*)/i';
$pat2 = '/:[a-z][_$0-9a-z]*/i';
$num = preg_match_all( $pat1, $qry, $regs);
$qry2 = preg_replace( $pat2, '?', $qry);
$vals = array();
for ( $ii = 0; $ii < $num; $ii++ ) {
$name = strtoupper($regs[1][$ii]);
// get parameter value from parameter name
$val = $arr[$name];
$vals[] = $val;
}
$resrc = ibase_pconnect (FB_DATABASE, FB_USERNAME, FB_PASSWORD);
if ( $resrc != false ) {
array_unshift($params, $resrc, $qry2 );
$result = call_user_func_array ( 'ibase_query', $params );
return $result;
}
}


Lester Caine ha scritto:
> I'm not sure I understand the problem Mimmo.
I'm sure I cannot have session in English at next Firebird Conference... :-)
Or, we will prepare a room where you can ROTFL for all the evening...

> Even in Delphi you have to keep
> the parameter order the same when running the query,
TParams after TQuery.prepare() are accessible through ParamByName().
Don't understand here (but it's off topic so don't go further)

> Your current 'library' must have some means of identifying which
> parameter goes with which '?' even if it is hidden, but suspect that
> information is not stored with the query?
The information is stored with the query, in the sense that I've already
queries in the form
SELECT 'A', 'B', K.THAT, K.THIS, K.OTHER FROM OK K WHERE K.GGG = :PARAM1
AND K.SSS = :PARAM1
This also says to me that there are two parameter with the same value
(PARAM1).
From another set of in memory information, i.e. a TStringList, I can
find PARAM1 and its value.
> THAT is how I
> suspect your Delphi application is working internally?
>
Yes, almost. See my solution and you can verify if I explained well my
question.

Ciao.
Mimmo.