Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: PERL and MySQL

by meraxes (Friar)
on Oct 19, 2007 at 15:14 UTC ( #646002=note: print w/ replies, xml ) Need Help??


in reply to PERL and MySQL

If I may suggest as well, doing this using sprintf is not ideal. Using placeholders is always a better idea:

my $sql = q{ SELECT `Cats`.`Name`, `Address`.`Address`, `Address`.`City`, `Contact`.`Phone`, `Keys`.`Keywords` FROM ( `Cats` LEFT JOIN `Address` USING (`Name`) LEFT JOIN `Contact` USING (`Name`) LEFT JOIN `Keys` USING (`Name`) ) WHERE `Keys`.`Keywords` LIKE ? ORDER BY `Cats`.`Name` asc LIMIT ?,? }; # get the statement handle, assuming a valid DBI object in $dbh my $sth = $dbh->prepare( $sql ); $sth->execute( '%'.$search.'%', $start - 1, $per_page + 1 );

You also had the "order by" clause stating name. I would have thought that'd be an error since you're not specifying the table in a join. I've changed it to `Cats`.`Name`.

update: I'm an idiot. Fixed execute syntax.

--
meraxes


Comment on Re: PERL and MySQL
Select or Download Code
Re^2: PERL and MySQL
by JimJx (Beadle) on Oct 20, 2007 at 07:13 UTC
    Thanks for all of the suggestions everyone!

    The '%%' was the culprit... Also, since I am working with a premade script of sorts here, I am just trying to get it to work, but I do plan on using placeholders when I get the time to do a rewrite. IMO the whole script needs it....

    Once again, thanks everyone!
    Jim

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (14)
As of 2014-12-18 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (61 votes), past polls