5

我有以下代码块,预计将返回count

    $sql = "SELECT sum(count) as count 
            FROM multipleowners WHERE owner = ? " . $localityquery;
    $queryarray = array($owner, $locality);
    $query = $this->db->query($sql, $queryarray);
    if ($query->num_rows() > 0)
    {
        $result = $query->row_array();
        $count = $result['count']; 
    }

但是当我尝试打印时,我得到了空值$count

我用过print_r($this->db->last_query());,我得到了以下查询,

SELECT sum(count) as count FROM multipleowners WHERE owner = 'Davenports Harbour Trustee (2012) Limited' and locality = 'Auckland Central'

当我直接在我的身上执行这个查询时,我Postgresql IDE得到了countas的输出2

这个查询会出现什么问题以及在哪里出错?我怀疑从句中(and)的存在。WHERE我该如何解决 ?

更新

当我启用探查器时,我得到了以下查询,

SELECT sum(count) as count 
            FROM multipleowners WHERE owner = 'Davenports Harbour Trustee (2012) Limited'  and locality = 'Auckland Central'

所以很明显问题存在于(and )!!

4

2 回答 2

2

答对了!!在将变量传递给查询之前,我添加了以下行$owner并且它起作用了,

$owner = html_entity_decode($owner);
于 2013-02-08T01:47:17.810 回答
0

您是否尝试过 select sum(db.[count] as icount,因为在语言中 count 也可能是保留字。所以将该字段括起来或重命名,尽量不要将新输出命名为 count..

于 2013-02-08T00:30:57.790 回答