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

Hello,

I'm trying to use a place holder in a DBI-MySQL sql statement but I am becoming unstuck when the condition on the SQL is a REGEXP thus.

$sth->prepare("SELECT COUNT(keyword) AS count FROM c3_keyword_list WHE +RE keyword REGEXP '^?'");


I assume it's because of the meaning the ? has in the reg ex.

Can anybody shed any light on this one please

Replies are listed 'Best First'.
Re: Using a DBI placeholder
by jasonk (Parson) on Mar 11, 2003 at 15:34 UTC

    By putting single quotes around it, it isn't a placeholder anymore...

    my $sth = $dbh->prepare("SELECT COUNT(keyword) AS count FROM c3_keywor +d_list WHERE keyword REGEXP ?"); $sth->execute('^foo');
Re: Using a DBI placeholder
by Tomte (Priest) on Mar 11, 2003 at 15:34 UTC

    I assume it is because it is in a String, you should try:
    ...REGEXP ?
    and then set the value with a ? prepended, e.g.

    ... $sth->bind_param($x, $value); ... $sth->execute();

    regards,
    tomte


    edit:striked out my foolishness

Re: Using a DBI placeholder
by bronto (Priest) on Mar 11, 2003 at 15:34 UTC

    What are you trying to do exactly? ^? is not that useful... maybe you wanted ^$, or what?

    Update: Ok, jasonk and Tomte shed some light on your question. I am sorry, I can't help.

    Ciao!
    --bronto


    The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
    --John M. Dlugosz