Re: prepare/execute in PEAR::DB
| From: | Stig S. Bakken | Date: | Fri, 16 Nov 2001 06:37:49 +0000 |
| Subject: | Re: prepare/execute in PEAR::DB | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-2919@lists.php.net to get a copy of this message | ||
Christian Stocker wrote:
>
> Hi out there
>
> can anyone explain me, what's the idea of prepare/execute in PEAR::DB?
>
> I came to some conclusions, but i'm not sure, if they are correct:
>
> 1. some RDBMS can preparse a prepare statement and don't have to that
> afterwards for each query.
>
> 2. the code looks nicer. I don't have to mix my SQL with variables and
> escaping-stuff.
>
> 3. perl-dbi does it that way, too :)
>
> are they wrong? are there more?
> please don't let me die stupid ;)
The most important reasons for using it are:
You don't have to worry about quoting (security and simplicity).
Prepare/execute lets you include the contents of files with the "&"
placeholder.
In Oracle (and maybe others), parsed queries are cached, if you use
"prepare" this caching will be more efficient because there are fewer
different queries (since the data are no longer part of them).
In databases with native prepare/execute/binding support you get a
significant performance gain when for example running the same insert 50
times with different data because the query is only parsed once.
- Stig