in reply to DBI Placeholders

In your select line you would change the hash{$comp_id} to a ?. Then when you call the SQL execute() function call it like this:
$sth=execute($hash{$comp_id});
I believe that should do what you want

-Adam Stanley
Nethosters, Inc.

Replies are listed 'Best First'.
Re: Re: DBI Placeholders
by qball (Beadle) on Apr 10, 2001 at 01:13 UTC
    Great comment, but what if I want to use the routine several times in the script using different variables?

    qball~"I have node idea?!"
      simply recall the execute() function with each different variable - you are not limited to using only the listed variable - you could even do it without a variable at all as in: execute("1"); Only by putting the variable in the $sql definition do you limite yourself to having to "re-prepare" the statement for every value you want to check.

      -Adam Stanley
      Nethosters, Inc.
Re: Re: DBI Placeholders
by astanley (Beadle) on Apr 10, 2001 at 01:07 UTC
    Forgot to mention one thing - you need to change the prepare function to prepare_cached otherwise the ? will cause it to fail.

    -Adam Stanley
    Nethosters, Inc.

      Nah, prepare is fine. The prepare_cache just saves the corresponding $sth. This may be faster depending on the DB, but as the docs note it may be risky.

      -ben

        To clarify, DBI takes care of saving the $sth. You don't have to worry about it. From the doc:
        Like prepare except that the statement handle returned will be stored +in a hash associated with the $dbh. If another call is made to prepar +e_cached with the same $statement and %attr values, then the correspo +nding cached $sth will be returned without contacting the database se +rver.
        So you go on about your business and let DBI worry the details.