Codeigniter数据库更新 [英] Codeigniter database update
问题描述
桌子是这样的
并且我想通过指定ArchiveID和RecipientID更新DecryptionDate
and I want to update DecryptionDate by specify ArchiveID and RecipientID
这是我的代码
$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";
}
我的问题是,仅当 $ archiveID
为911并且 $ userID
为test01时,我才能更新数据,但是当 $ archiveID 时,程序无法更新code>是911,
$ userID
是test02
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
在添加 echo $ this-> db-> last_query();
之后,我已经
UPDATE
log
SETDecryptionDate
='2011-11-16 20:01:39'WHEREArchiveID
='911'AND收件人ID
='test01'
UPDATE
log
SETDecryptionDate
= '2011-11-16 20:01:39' WHEREArchiveID
= '911' ANDRecipientID
= 'test01'
当ArchiveID为test01并且更新为SUCCESS
when ArchiveID is test01 and the update is SUCCESS
和
UPDATE
log
SETDecryptionDate
='2011-11-16 20:03:10'WHEREArchiveID
='911'AND收件人ID
='test02'
UPDATE
log
SETDecryptionDate
= '2011-11-16 20:03:10' WHEREArchiveID
= '911' ANDRecipientID
= 'test02'
当ArchiveID为test02且更新为FAIL
when ArchiveID is test02 and the update is FAIL
我已经尝试过
$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;
}
但结果仍然相同
并尝试仅检查这样的RecipientID
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;
}
仅使用与 RecipientID
匹配的记录,而不与其他记录重复的 ArchiveID
匹配的记录,使更新成功
make the update success with only record that match with the RecipientID
but not with duplicate ArchiveID
with other record
像这样
最后,我用以下代码(而不是通过CI)测试了通用php文件的更新,结果是失败
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 ");
}
所以我认为这一定是数据库问题
这是数据库结构
并且ArchiveID和RecipientID是索引
and ArchiveID and RecipientID are index
推荐答案
我尝试从数据库中导出数据并对其进行截断,然后再将其导入回来,这可以解决问题.
I try export the data from database and truncate it then import the data back, it can help, the problem solved.
这篇关于Codeigniter数据库更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!