in reply to bind not working with DBI?

Try adding the type parameter to bind_param:
use DBI qw(:sql_types); ... $sth->bind_param(1, $_, SQL_VARCHAR); # or whatever type it is

Replies are listed 'Best First'.
Re: Re: bind not working with DBI?
by Grygonos (Chaplain) on Jul 30, 2003 at 00:25 UTC
    try making your sql statement like this
    my $query = q{select distinct account, account_id, company, the_date from account_information where account_id = ?}; my $sth = $dbh->prepare($query); $sth->execute($_);
    That way the quoting is handled by the dbd (if i'm not mistaken)

    If you'd like to not use the q{} construct you can try this.
    my $query = "select distinct account, account_id, company, the_date from account_information where account_id = ?"; my $sth = $dbh->prepare($query); $sth->execute($dbh->quote($_));

    just some ideas and different ways I've prepared dbi queries for execution. If any of the methods I used aren't in your version of DBI, please know I wasn't trying to be rude. I'm just not familiar with DBI's history other that what I've used.

    Hope some of this helps.
Re: Re: bind not working with DBI?
by GhodMode (Pilgrim) on Jul 30, 2003 at 16:17 UTC
    I'm not familiar with the qw(:sql_types) part. I know that I can quote some subroutine name after the module name on the use line to only import that subroutine into the main package, but I didn't see a sql_types subroutine in the documentation for DBI 1.13. What's the colon supposed to do?

    I did try specifying the type parameter for the bind_param method. I used the number 12 instead of the descriptive name (VARCHAR2). I got that number after printing out all of the types for this database using the type_info_all database handle method.

    I still haven't had any luck.

    GM
      I'm not familiar with the qw(:sql_types) part. ... I didn't see a sql_types subroutine in the documentation for DBI 1.13.
      It was added in 0.88, so I believe you should have it. It imports sql type constants such as 'SQL_VARCHAR'. You can see what it imports with this (which is straight from the DBI docs):
      foreach (@{ $DBI::EXPORT_TAGS{sql_types} }) { printf "%s=%d\n", $_, &{"DBI::$_"}; }