Subject Re: [firebird-php] Paramter Queries
Author Lester Caine
Robert martin wrote:
> I was using PDO for other Dbs but have switched to using the
> firebird/interbase drivers as the PDO firebird stuff was full of bugs.

The PDO stuff DOES need work, but those of us who actually use Firebird
have other more flexible ways of handling databases on PHP, so are not
prepared to spend time on something which only does half the job anyway.
ADOdb will provide cross database support for the SQL rather than just
some aspects of the data.

> Anyway I have got my php connecting, disconnecting and using
> transactions ok. However I am struggling with running queries that take
> parameters. In the PDO drivers I used a bindparam function to assign a
> value to a named parameter. However I cant see an equivelent function
> for the native drivers. I see that ibase_execute and ibase_Query take a
> 'bind_arg' list of parameters that fill in '?' indicated parameters.
>
> First Question
> I would like to do queries like "Update TableName SET Field1 =
> :Field1Param WHERE Field2 = :Field2param" and assing parameters by
> name. IS this at all possible ?

Not even with ADOdb, at the end of the day the dtat HAS to be converted
to ->

> If I do have to use "Update TableName SET Field1 = ? WHERE Field2 = ?" I
> have found the following function (which I don't fully understand) that
> takes an array of params and runs an execute. I am using it and it
> appears to work well.

Anyway ;)

> function db_execute($stmt, $data)
> {
> if(!is_array($data))
> return ibase_execute($stmt,$data);
>
> $params = array();
> while( list($k,$v) = each($data) )
> $params[$k] = '$data['.$k.']';
> eval('$rc=ibase_execute($stmt,'.join(',',$params).');');
>
> return $rc;
> }

Looks about right - ADOdb does something similar.

> If I am using the above and I want to pass in Blob (binary) data as 1 or
> more of the params I suspect the above will fail, correct?
>
> If so what should I do?
As you have found - this works. Or you can use ibase_blob_import to load
a parameter handle for a blob with a file, such as on image, and include
that in the params array.

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php