views:

71

answers:

1

This one's puzzling me. I have a MySQL query, being run though PDO:

$stmt = $db->prepare( "UPDATE member SET acode='' AND status='active' WHERE username=:u" );
$stmt->bindValue( ':u', $member->username, PDO::PARAM_STR );
$stmt->execute();

The acode field gets set to 0 for some reason. It was created with

`acode` varchar(8) NOT NULL

Is there something special I need to do when using prepared statements?

+8  A: 

Gidday,

The problem comes with this part of your query:

SET acode='' AND status='active'

the AND turns this into the boolean check of '' AND status='active', which evaluates to 0. Change your query to:

SET acode='', status='active'
Fritz H
D'oh! Schoolboy error, can't believe I missed that...
DisgruntledGoat
Heh, it happens - much like my all-too-common habit of doing an `UPDATE` on a Parameters table and forgetting the `WHERE` clause!
Fritz H