perl - How to implement sql LIKE qualifier with placeholdes for an array? -


I am trying to implement SQL as a qualifier with placeholders for a set of standards. I know how to do this for a particular price:

  Use strict; Use DBI; My $ dbh = dbi- & gt; Connect ("DBI: Sybase: Server = $ Srv; Database = $ Db", "$ user", "$ passwd") or "Can not connect to database"; My $ query = "Select key, first_name where the last_name is preferred?"; My $ sth = $ dbh- & gt; Could not prepare prepared ($ query) or die "statement \ n", $ dbh-> Errstr; $ Sth- & gt; Bind_param (1, "march%") or die may not be "bund_prim", $ sth- & gt; Errstr; $ Sth- & gt; Executed or killed "$ query could not be executed", $ sth- & gt; Errstr; While (my @ root = $ sth-> fetchrow_array) {print "@result \ n"; }  

When I try to implement the above code for the set of values ​​present in the array @l_names , I do not get any results. I am doing it as follows:

  Use strict; Use DBI; Open (FH, "/ home / usr / file") or die $ !; My @ l_names = & lt; FH> Close (FH); My $ dbh = dbi- & gt; Connect ("DBI: Sybase: Server = $ Srv; Database = $ Db", "$ user", "$ passwd") or "Can not connect to database"; My $ query = "Select key, first_name where the last_name is preferred?"; My $ sth = $ dbh- & gt; Could not prepare prepared ($ query) or die "statement \ n", $ dbh-> Errstr; Foreach My $ l_name (@l_names) {$ sth- & gt; Bind_param (1, "$ l_name%") or dead "bund_primple", $ sth- & gt; Errstr; $ Sth- & gt; Executed or killed "$ query could not be executed", $ sth- & gt; Errstr; } (While my @ root = $ sth-> fetchrow_array) {print "@result \ n"; }  

Any suggestions on what's going wrong and how to fix it? Thanks!

You have not removed the EOL marker from the line that you have read from the file. Here's why:

  my @l_names = & lt; FH> Chomp (@l_names);  

Update:

You can also look at the question


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -