why does $dbh->do stmt work and not dbh->prepare
am 11.04.2008 03:42:20 von mmccaws
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
Re: why does $dbh->do stmt work and not dbh->prepare
am 11.04.2008 10:48:38 von Martin.Evans
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
Re: why does $dbh->do stmt work and not dbh->prepare
am 11.04.2008 13:30:46 von mdorman
On Fri, 11 Apr 2008 09:48:38 +0100
Martin Evans 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.