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

DBI Named Placeholders

by dilyin (Initiate)
on Jan 14, 2011 at 14:19 UTC ( [id://882342]=perlquestion: print w/replies, xml ) Need Help??

dilyin has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Monks!

Does DBI/DBD-MySQL support named placeholders?

from cpan:
Some drivers also allow placeholders like :name and :N (e.g., :1, :2, and so on) in addition to ?, but their use is not portable.

code like this:

$sth = $dbh->prepare('SELECT * FROM modules WHERE module LIKE :m A +ND code LIKE :c'); $sth->bind_param(':m', "%v%"); $sth->bind_param(':c', "%x%"); $rv = $sth->execute;
It doesn't work, maybe incorrect syntax.

? placeholders becomes total mess if you have more then 30 of them and have to calculate order

I found 2003 year post here that tells that DBD-mysql doesn't support named placeholders. Did anything change?

PHP/PDO does have named placeholders:
<?php /* Execute a prepared statement by binding PHP variables */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindParam(':calories', $calories, PDO::PARAM_INT); $sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12); $sth->execute(); ?>

Replies are listed 'Best First'.
Re: DBI Named Placeholders
by Anonymous Monk on Jan 14, 2011 at 14:55 UTC
Re: DBI Named Placeholders
by trwww (Priest) on Jan 14, 2011 at 18:00 UTC

    placeholders becomes total mess if you have more then 30 of them and have to calculate order

    I use MySQL but don't really need to worry about these things because I also use DBIx::Class. If you are worrying about your inserts being slow because of it (though I doubt they will), use the same thing DBIx::Class uses to generate SQL: SQL::Abstract.

Re: DBI Named Placeholders
by Anonymous Monk on Jan 14, 2011 at 14:54 UTC
    Did anything change?

    What did the DBD::mysql documentation say?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://882342]
Approved by jfroebe
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found