PHP Programer / New to PERL need DBI MySQL Help

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 1
Reputation: webdude12 is an unknown quantity at this point 
Solved Threads: 0
webdude12 webdude12 is offline Offline
Newbie Poster

PHP Programer / New to PERL need DBI MySQL Help

 
0
  #1
Oct 15th, 2008
I have a PHP script I am trying to convert to PERL and need some help.

Here is the code in PHP
  1. $store_list_name = $prod[10];
  2. $category = $prod[11];
  3. $sub_category = $prod[12];
  4.  
  5. $searchfor = $store_list_name . "->" . $category . "->" . $sub_category;
  6. $getcat = mysql_query("SELECT * FROM categories WHERE (overstock_id LIKE '%|".addslashes($searchfor)."|%');",$link);
  7. while ($p_row =mysql_fetch_array ($getcat) ) {
  8. $cat_name = stripslashes($p_row[cat_name]);
  9. $cat_id = $p_row[cat_id];
  10. $sub_of = $p_row[sub_of];
  11. }

Here is what I have in PERL:
  1. my $searchfor = $store_list_name . "->" . $category . "->" . $sub_category;
  2. my $search_by = $dbh->quote($searchfor);
  3. my $query = "SELECT * FROM categories WHERE overstock_id %|".$searchfor."|%";
  4. my $dth = $dbh->prepare($query);
  5. $dth->execute();
  6. my $ref;
  7. while ($ref = $dth->fetchrow_hashref())
  8. {
  9. my $master_cat = $ref->{cat_id};
  10. my $sub_cat = $ref->{sub_of};
  11. }

The problem I am running into is, I get this error:
DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '|Tools->Professional Grade Tools->Tool Sets|%' at line 1 at ./test.pl line 57, <CSV> line 585.

My first % is going bye bye.... Can some one help?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: mattjmorrison is an unknown quantity at this point 
Solved Threads: 0
mattjmorrison mattjmorrison is offline Offline
Newbie Poster

Re: PHP Programer / New to PERL need DBI MySQL Help

 
0
  #2
Nov 25th, 2008
Perl uses the % to prefix names of associative arrays (hashes)...and since Perl interpolates double quoted strings you'll need to escape the % symbols....also, i believe your missing the word "LIKE" in your query....you also may want to add an "or die($dbh->errstr)" on your prepare and execute calls.
Come visit us at our Software Developer Group!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 78
Reputation: chrisranjana is an unknown quantity at this point 
Solved Threads: 3
chrisranjana chrisranjana is offline Offline
Junior Poster in Training

PHP Programer / New to PERL need DBI MySQL Help examples

 
0
  #3
Dec 3rd, 2008
Here are some perl dbi examples
Chris, Director, Chrisranjana.com
Web developers and software programmers.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC