Re: DBI update
- From: Fabian Pilkowski <pilkowsk@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 15 Apr 2005 00:52:08 +0200
* Bigus schrieb:
> In the following snippet of code, I'm trying to update several fields in a
> database record:
>
> my $sth = $db->prepare("UPDATE items SET $set WHERE id = '$form{selitem}'");
> $sth->execute($quoted);
>
> $set, in the prepare statement, is a string that contains field/value pairs
> like this:
>
> "type = ?, size = ?, description = NULL"
>
> then in the execute line $quoted is a string containing the bind variables
>
> "$form{type},$form{size}"
>
> So what I'm trying to achieve is the equivalent of:
>
> my $sth = $db->prepare("UPDATE items SET type = ?, size = ?, description =
> NULL WHERE id = '$form{selitem}'");
> $sth->execute($form{type},$form{size});
>
> Now the prepare statement works fine but the db error:
>
> "called with 1 bind variables when 2 are needed"
Sure, the whole content of $quoted is seen as one argument. It would be
used for the "type = ?" part of your sql-statement. What you want to do
is some kind of splitting into an array with 2 elements:
my @bind = split /,/, $quoted, 2;
$sth->execute( @bind );
# shortened to:
$sth->execute( split /,/, $quoted, 2 );
Perhaps you could pay attention on this when building the var $quoted
and save your values in an array rather than a skalar.
regards,
fabian
.
- Follow-Ups:
- Re: DBI update
- From: Bigus
- Re: DBI update
- References:
- DBI update
- From: Bigus
- DBI update
- Prev by Date: Re: Source Code for Beginning Perl by Simon Cozens
- Next by Date: Re: Matching mixed up words
- Previous by thread: Re: DBI update
- Next by thread: Re: DBI update
- Index(es):
Relevant Pages
|