why does $dbh->do stmt work and not dbh->prepare

Hi

the dbh->do stmts work but the prepare stmts don't for updates.



$dbh->do("UPDATE proj_trckr SET curr_date='$ucurrdate'
WHERE proj_id='$resetinactive' ") or die;
$dbh->do("UPDATE proj_trckr SET curr_date='$neg'
WHERE proj_id='$resetprojid' ") or die;

but these don't
------>
my $resetprojid = 'April 03, 2008';
my $resetinactive = 'INACTIVE PROJECT';
my $ucurrdate = 'yes';

my $sth= $dbh->prepare('UPDATE proj_trckr SET curr_date=?
WHERE proj_id=?');
$sth->execute($resetinactive, $ucurrdate);

my $sth= $dbh->prepare('UPDATE proj_trckr SET curr_date=?
WHERE proj_id=?');
$sth->execute($resetprojid, 'no');

----->

Thanks
Mike
mmccaws [ Fr, 11 April 2008 03:42 ] [ ID #1940934 ]

Re: why does $dbh->do stmt work and not dbh->prepare

mmccaws2 wrote:
> Hi
>
> the dbh->do stmts work but the prepare stmts don't for updates.
>
>
>
> $dbh->do("UPDATE proj_trckr SET curr_date='$ucurrdate'
> WHERE proj_id='$resetinactive' ") or die;
> $dbh->do("UPDATE proj_trckr SET curr_date='$neg'
> WHERE proj_id='$resetprojid' ") or die;
>
> but these don't
> ------>
> my $resetprojid = 'April 03, 2008';
> my $resetinactive = 'INACTIVE PROJECT';
> my $ucurrdate = 'yes';
>
> my $sth= $dbh->prepare('UPDATE proj_trckr SET curr_date=?
> WHERE proj_id=?');
> $sth->execute($resetinactive, $ucurrdate);
>
> my $sth= $dbh->prepare('UPDATE proj_trckr SET curr_date=?
> WHERE proj_id=?');
> $sth->execute($resetprojid, 'no');
>
> ----->

Mike,

Some things to may be look at:

1. Your do and prepare/execute examples don't look the same to me e.g.,
they use different curr_date values.

2. You don't state if you have RaiseError/PrintError set and there is no
error checking of the prepare or execute methods.

3. Have you got AutoCommit enabled because you don't state whether you
have committed your updates via prepare/execute.

Martin
--
Martin J. Evans
Easysoft Limited
http://www.easysoft.com
Martin.Evans [ Fr, 11 April 2008 10:48 ] [ ID #1940936 ]

Re: why does $dbh->do stmt work and not dbh->prepare

On Fri, 11 Apr 2008 09:48:38 +0100
Martin Evans <martin.evans [at] easysoft.com> wrote:

> mmccaws2 wrote:
> > $dbh->do("UPDATE proj_trckr SET curr_date='$ucurrdate'
> > WHERE proj_id='$resetinactive' ") or die;

> > my $sth= $dbh->prepare('UPDATE proj_trckr SET curr_date=?
> > WHERE proj_id=?');
> > $sth->execute($resetinactive, $ucurrdate);
>
> Mike,
>
> Some things to may be look at:
>
> 1. Your do and prepare/execute examples don't look the same to me
> e.g., they use different curr_date values.

Even more specifically, they seem to have their values backwards---in
the ones that work $resetinactive corresponds to proj_id, but in the
latter ones he's associating that variable with curr_date.

Mike.
mdorman [ Fr, 11 April 2008 13:30 ] [ ID #1940937 ]
Perl » perl.dbi.users » why does $dbh->do stmt work and not dbh->prepare

Vorheriges Thema: Re: DB2.xs error
Nächstes Thema: RE: question for DBD-Oracle driver