我想在名为 SIZE
(整数)的列中添加1,这是我的查询:
$this->dbsections->update('sections', "SIZE = SIZE + 1");
但是在错误消息中,它显示为:
UPDATE `sections` SET `SIZE = SIZE +` 1 = '' WHERE `NAME` = 'ABC'
答案 0 :(得分:3)
您可以重写更新查询
public class EmailBuilder
{
public string Sender { get; set; }
public string Receiver { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public int SmtpServerPort { get; set; }
public string SmtpServerAddress { get; set; }
private MailMessage _mail;
public EmailBuilder()
{
this._mail = new MailMessage();
this.SmtpServerAddress = CmsConstants.smtpServerAddress;
this.SmtpServerPort = CmsConstants.smtpServerPort;
}
public void SetEmail(string receiver, string subject, string body)
{
this._mail.To.Add(receiver);
this._mail.From = new MailAddress("noreply@noreply.se");
this._mail.Subject = subject;
this._mail.Body = body;
this._mail.Bcc.Add("noreply@noreply.se");
}
}
set()也会接受一个可选的第三个参数($ escape) 如果设置为FALSE
,将阻止数据被转义
阅读https://www.codeigniter.com/userguide3/database/query_builder.html#updating-data
答案 1 :(得分:2)
你可以试试这个:
$this->dbsections->query("UPDATE sections SET SIZE = SIZE + 1 WHERE NAME = 'ABC'");