我现在面临着非常奇怪的情况。我在 CodeIgniter 中使用如下 WHERE 条件编写了一个查询:
$queryps = $this->db->query("SELECT count(workorderno) as total from crm_workorder where workorderno =".$sitecode."");
但是我收到了这个错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
SELECT count(workorderno) as total from crm_workorder where workorderno =
现在奇怪的是变量 $sitecode
不是空的。当我回显查询时,它显示如下:
SELECT count(workorderno) as total from crm_workorder where workorderno =2
但是在 SQL 查询中,我遇到了上述错误。 WHERE 条件下没有任何内容。
我尝试了各种可能的方法来找出背后的原因,但我无法弄清楚这一点。谢谢。
最佳答案
这就是您所需要的,它必须在您的模型中。
<?php
$this->db->select("SELECT count(workorderno) as total");
$this->db->from("crm_workorder");
$this->db->where("workorderno",$sitecode);
$queryps = $this->db->get();
?>
关于php - $this->query() 中条件为空的 Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53884387/