| | |
PHP Programer / New to PERL need DBI MySQL Help
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Solved Threads: 0
I have a PHP script I am trying to convert to PERL and need some help.
Here is the code in PHP
Here is what I have in PERL:
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?
Here is the code in PHP
Perl Syntax (Toggle Plain Text)
$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:
Perl Syntax (Toggle Plain Text)
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?
•
•
Join Date: Nov 2008
Posts: 6
Reputation:
Solved Threads: 0
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!
•
•
Join Date: Jul 2005
Posts: 78
Reputation:
Solved Threads: 3
Here are some perl dbi examples
Chris, Director, Chrisranjana.com
Web developers and software programmers.
Web developers and software programmers.
![]() |
Other Threads in the Perl Forum
- Previous Thread: Perl and Facebook
- Next Thread: cygwin, make, perl, win32::ole (excel) problem
| Thread Tools | Search this Thread |





