编程技术网

关注微信公众号,定时推送前沿、专业、深度的编程技术资料。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

极客时间

Codeigniter数据库更新:Codeigniter database update

chl hive 2022-5-10 14:22 12人围观

腾讯云服务器

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 SET DecryptionDate ='2011-11-16 20:01:39'WHERE ArchiveID ='911'AND 收件人ID ='test01'

UPDATE log SET DecryptionDate = '2011-11-16 20:01:39' WHERE ArchiveID = '911' AND RecipientID = 'test01'

当ArchiveID为test01并且更新为SUCCESS

when ArchiveID is test01 and the update is SUCCESS

UPDATE log SET DecryptionDate ='2011-11-16 20:03:10'WHERE ArchiveID ='911'AND 收件人ID ='test02'

UPDATE log SET DecryptionDate = '2011-11-16 20:03:10' WHERE ArchiveID = '911' AND RecipientID = '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 Archive AND Recipient 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 Recipient 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 Archive AND Recipient "; $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数据库更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!

腾讯云服务器 阿里云服务器
关注微信
^