> 
> 
> On Mon, Nov 25, 2002 at 07:48:14AM -0800, Michael A Chase wrote:
> > > I'm assuming that the first time the statement is executed 
> something is
> > > trying to work out whether the field is numeric or string, 
> and seeing a
> > > number, assumes it's numeric. But then, every future insert 
> fails, with
> > > a highly misleading error ...
> > 
> > DBI remembers the types of placeholders after the first use.  Either
> > enclose the number in quotes to make it a string or call 
> bind_param() with
> > a dummy value that can't get confused for a number before you call
> > execute() the first time.
> 
> Yes, this is what I assumed. But consider a case where, for example, the
> value is coming in from a form, in a mod-perl based environment, where
> you've used prepare_cached.
> 
> Does this mean that best practice is to do something like:
>       $insert->execute("$username", "$password");
> just in case the first person to use the form happens to use a numeric
> value as input? 

It may be better to use, at the top of the script:
        use strict;
        use DBI qw(:sql_types);
        
and later:

        $insert = $dbh->prepare($sql);
        $insert->bind_param(1, undef, { TYPE => SQL_VARCHAR });
        $insert->bind_param(2, undef, { TYPE => SQL_VARCHAR });

        # now use it knowing that the type is set to SQL_VARCHAR....

> 
> Seems a little strange and underdocumented...
> 
> And there's still the matter of the highly misleading error message:
>  DBD::mysql::st execute failed: Unknown column 'nine' in 'field list'
> 
> The error of course being nothing to do with a column 'nine', as that's
> the value being passed to it...
> 

Jeff

Reply via email to