Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: sql select with array

by busunsl (Vicar)
on Oct 22, 2001 at 13:26 UTC ( [id://120474]=note: print w/replies, xml ) Need Help??


in reply to sql select with array

Please enclose your code in code-tags, read the help pages about that.

Now to your problem:

You have to join your column names like this:

my $row = $dbh->selectall_arrayref('select ' . join(',', @selector) . " from people where (fornavn like '%$search%') or (efternavn like '%$s +earch%') or (cpr LIKE '%$search%')",\ %attr);

Replies are listed 'Best First'.
Re: sql select with array
by Ranna (Acolyte) on Oct 23, 2001 at 07:41 UTC
    Or, if you're not stuck on using just $dbh->selectall_arrayref and your database supports placeholders, couldn' you do this?
    $sth = $dbh->prepare("SELECT " . '? ' x $#selector . "FROM people WHER +E (fornavn LIKE '%$search%') or (eternavn LIKE '%$search%') or (cpr L +IKE '%$search%'", \%attr); #dunno if you can do the \%attr part... $sth->execute(@selector);
    And then you've got a statement handle to get your data from.. I don't know if it's more efficient, but it seems a bit more readable to me.
      No, you can't. Placeholders are allowed in where clauses and as update values only.

      Well, _some_ DBD's support them in the way you'd use them, but I wouldn't rely on that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://120474]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-24 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found