I have a PHP script I am trying to convert to PERL and need some help.

Here is the code in PHP

$store_list_name = $prod[10];
    $category = $prod[11];
    $sub_category = $prod[12];

    $searchfor = $store_list_name . "->" . $category . "->" . $sub_category;
    $getcat = mysql_query("SELECT * FROM categories WHERE (overstock_id LIKE '%|".addslashes($searchfor)."|%');",$link);
    while ($p_row =mysql_fetch_array ($getcat) ) {
    $cat_name = stripslashes($p_row[cat_name]);
    $cat_id = $p_row[cat_id];
    $sub_of = $p_row[sub_of];
    }

Here is what I have in PERL:

my $searchfor = $store_list_name . "->" . $category . "->" . $sub_category;
    my $search_by = $dbh->quote($searchfor);
    my $query = "SELECT * FROM categories WHERE overstock_id %|".$searchfor."|%";
    my $dth = $dbh->prepare($query);  
    $dth->execute();
    my $ref;
    while ($ref = $dth->fetchrow_hashref())
    {
    my $master_cat = $ref->{cat_id};
    my $sub_cat = $ref->{sub_of};
    }

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?

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.