The table is like this
and I want to update DecryptionDate by specify ArchiveID and RecipientID
this is my code
$this->load->database();
$date = date("Y-m-d H:i:s");
$data = array('DecryptionDate' => $date);
$array = array('ArchiveID'=>$archiveID.'','RecipientID'=>$userID.'');
$this->db->where($array);
$this->db->update('log', $data);
if ($this->db->affected_rows() > 0) {
echo "SUCCESS";
} else {
echo "FAIL";
}
my problem is I can update the data only when $archiveID
is 911 and $userID
is test01 but the program fail to update when $archiveID
is 911 and $userID
is test02
after added echo $this->db->last_query();
I've got
UPDATE
log
SETDecryptionDate
= '2011-11-16 20:01:39' WHEREArchiveID
= '911' ANDRecipientID
= 'test01'
when ArchiveID is test01 and the update is SUCCESS
and
UPDATE
log
SETDecryptionDate
= '2011-11-16 20:03:10' WHEREArchiveID
= '911' ANDRecipientID
= 'test02'
when ArchiveID is test02 and the update is FAIL
I've try this
$this->load->database();
$date = date("Y-m-d H:i:s");
$this->db->query('UPDATE log
SET DecryptionDate = \''.$date.'\'
WHERE ArchiveID = \''.$archiveID.'\' AND RecipientID = \''.$userID.'\'');
if ($this->db->affected_rows() > 0) {
echo "SUCCESS";
return TRUE;
} else {
echo "FAIL";
return FALSE;
}
but the result's still the same
and try check only the RecipientID like this
$this->load->database();
$date = date("Y-m-d H:i:s");
$this->db->query('UPDATE log
SET DecryptionDate = \''.$date.'\'
WHERE RecipientID = \''.$userID.'\'');
if ($this->db->affected_rows() > 0) {
echo "SUCCESS";
return TRUE;
} else {
echo "FAIL";
return FALSE;
}
make the update success with only record that match with the RecipientID
but not with duplicate ArchiveID
with other record
like this
Finally, I've test update with common php file with following code instead of via CI and also result is fail
$date = date("Y-m-d H:i:s");
$strSQL = "UPDATE log SET DecryptionDate = '".$date."' WHERE ArchiveID = '911' AND RecipientID = 'test02' ";
$objQuery = mysql_query($strSQL);
if( mysql_affected_rows($objQuery) != 0 )
{
echo (" SUCCESS ");
} else {
echo (" FAIL ");
}
so I think this must be database problem
here is the DB structure
and ArchiveID and RecipientID are index