0

我正在使用 codeigniter 并且正在执行此查询

SELECT c.id AS id, c.name AS name, c.img_add AS img, c.downloads as down, c.tag as tag, c.date as date,c.views as view FROM core c WHERE c.name = 'Ganesha (2)' ORDER BY c.downloads DESC

该查询在模型中使用,并且不返回任何数据,而在 Heidi SQL 中执行相同的查询时,会返回适当的数据。

我不知道天气是查询问题、codeigniter 问题还是 php 问题,所以我为所有人发帖。

这是我在我的 codeigniter 模型中编写的代码。这可能有助于回答。

public function getFolderDetail($folder) {

    $sql = "SELECT c.id AS `id`, c.name AS `name`, c.img_add AS `img`, c.downloads as `down`, c.tag as `tag`, c.date as `date`,c.views as `view` FROM core c
            WHERE c.name = ?
            ORDER BY c.downloads DESC";
    $params = array($folder);
    return $query = $this->db->query($sql,$params);
}
4

3 回答 3

1

我的怀疑可能是保留字,并且可能需要tick在它们周围标记。我会从你的

 `name`, `date` and `view` columns... 

勾号是键盘上 #1 左侧的 ` 键,而不是单引号

可能保留的每个部分都需要刻度线......例如

c.`name` as `name` (same with others) 

它适用于 where 子句

where c.`name` = 'something'

您是否遇到了无效功能?

通过发送您提到的“Alexa (2)”字符串,它可能会将其解释为一个名为“Alexa”的函数,并且它传递的参数为 2,因此 Alexa 不是一个真正的函数。您可以尝试不使用括号作为值吗?

这是 MySQL 保留字的列表

于 2013-11-10T14:06:40.153 回答
0

尝试转义保留字“日期”

SELECT `c`.`date` as `date` etc...

http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html

于 2013-11-10T14:26:12.753 回答
0

Ganesh (2)我遇到了问题,实际上文件夹中的值Ganesha (2)是值的 url 格式,因为我将此值作为 url 发送。

我做了这个

public function getFolderDetail($folder) {
$folder = str_replace(')',')',$folder);
$folder = str_replace('(','(',$folder);
    //echo $folder = str_replace('(','\(',$folder);

    $sql = "SELECT c.id AS `id`, c.name AS `name`, c.img_add AS `img`, c.downloads as `down`, c.tag as `tag`, c.date as `date`,c.views as `view` FROM core c
            WHERE c.name = ?
            ORDER BY c.downloads DESC";
    $params = array($folder);
    return $query = $this->db->query($sql,$params);
}

现在代码工作正常。

于 2013-11-15T14:53:43.453 回答