RE: [PEAR] Placeholder queries
| From: | Lukas Smith | Date: | Thu, 10 Apr 2003 12:44:54 +0000 |
| Subject: | RE: [PEAR] Placeholder queries | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-4780@lists.php.net to get a copy of this message | ||
> From: Jeroen Houben [mailto:jeroen@terena.nl]
> Sent: Thursday, April 10, 2003 2:34 PM
> In this month's PHP magazine I read that with PEAR::DB you can do
> placeholder queries like this:
>
> $file = '/tmp/image.png';
> $sql = 'INSERT INTO mytable (id, myblob) VALUES (?,&)';
> $id = $conn->nextId('mytable_id');
> $conn->query($sql, array($id, $file));
>
> I was familiar with prepared queries using a questionmark. What was
new
> to me, and perhaps to a lot of people, is that the '&' symbol will be
> replaced with the contents of the file. Very cool. Does this (or
> something similar) also work in PEAR::MDB ?
PEAR::DB also has "!" for values what will directly be used (like
integers).
Well I have been banging my head on that one a bit. Unfortunately nobody
ever replied to my questions on the PEAR mailinglists.
Basically PEAR::DB splits things up in 3 different types:
1) Data that needs to be quoted
2) Data that can be left as is
3) LOBs
This does not sufficiently abstract things however. MDB supports other
datatypes as well that might need special attention (like timestamps).
As such MDB has the following datatypes:
1) Text data type
2) Boolean data type
3) Integer data type
4) Decimal data type
5) Float data type
6) Date data type
7) Time data type
8) Time stamp data type
9) Binary Large object (file) data types
10) Character Large object (file) data types
6-8 can be combined into one datatype for this purposes.
So we could use ? for text, ! for integers and & for blobs. What happens
with the other datatypes?
As such MDB currently only offers ? and the user is responsible to
passing the types in a separate array.
Regards,
Lukas