I was not aware of placeholders, and the benifits of using them instead of
using $dbh->quote(). It doesnt make sence that the DBI version of quote isnt
as thorough as having the code behind placeholding do it. But anyhow, I have
a few questions as to how this works. Here is an example from the Perl
DBH::mysql docs:

my @names = ['Flaherty', 'Jones', 'Smith'];
my $sth = $dbh->prepare("UPDATE contact
                         SET phone = '555-1212'
                         WHERE last_name = ?");
$sth->execute(@names);
$sth->finish;

So most likely this query will return 3 rows, each corresponding to the last
names contained in the array. Does this mean you can not use more than one
place holder per query? What if the 'WHERE' statement was "WHERE last_name =
? AND first_name = ?". So you do an execute like this:
$sth->execute(@lnames,@fnames) ... This would not work because as far as the
execute function is concerned, these two arrays are the same (if you want to
pass them as seperate arguments you must pass references rather than the
object itself). Anyhow one how placeholders for multiple variables can be
used? Thanks.

ryan

> r> Seems that you are not taking advantage of Perl. This is what you can
do:
>
> No, he is taking advantage of placeholders. It is much better to use
> placeholder for value substitution that substitute values directly
> into query with Perl because there is no need to escape values (do you
> know that $dbh->quote doesn't quote reliably?) and $sth can be reused
> for simular queries (which can give perfomance gain on some SQL
> databases).
>
> However usually placeholders can be used only for value
> substitutuion. 'DESC' cannot be substituted since it is a part of
> query.
>
> r> $parentid = x;
> r> $orderby = 'DESC';
> r>    my $sth = $dbh -> prepare (qq{
> r>          SELECT message.name, contents, user.name, message.id
> r>          FROM message, user
> r>          WHERE folder='N' and parentid=$parentid
> r>          GROUP BY message.id
> r>          ORDER BY time $orderby
> r>          }) || die $dbh->errstr;
>
> r> You can put any variable inside the string... Note that I changed the
q{
> r> ... } to qq{ ... }
>
> r> $string = q{ string } is the same as $string = 'string';
> r> $string = qq{ string } is the same as $string = "string";
>
> r> Note that variables inside of strings enclosed by '' will not be
translated,
> r> only strings enclosed by "" (or qq{} =) ).
>
> --
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> | Ilya Martynov (http://martynov.org/)
|
> | GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6
|
> | AGAVA Software Company (http://www.agava.com/)
|
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to