Home  >  Article  >  Backend Development  >  mysql - thinkphp的where中使用id字段时的异常?

mysql - thinkphp的where中使用id字段时的异常?

WBOY
WBOYOriginal
2016-06-06 20:08:36960browse

<code>    $n=M("Nav");
    $name=$n->where(array('id'=>4))->find();
    echo $n->getLastSql();
    </code>

输出的结果是:

<code>SELECT * FROM `aa_nav` LIMIT 1
</code>

为什么where条件没有了?
当我where条件不用数组,而用字符串的时候就没问题。

回复内容:

<code>    $n=M("Nav");
    $name=$n->where(array('id'=>4))->find();
    echo $n->getLastSql();
    </code>

输出的结果是:

<code>SELECT * FROM `aa_nav` LIMIT 1
</code>

为什么where条件没有了?
当我where条件不用数组,而用字符串的时候就没问题。

thinkphp 3.2.3 表示一切正常,可以用array

不清楚是否是版本问题,3.x版是不会有这个问题的。

<code>['id']=4</code>

应该可以

确认有id这个字段?

问题解决了,说明一下具体情况:
1.用mysql-front工具建的表,默认的情况下有一个自增的列名为"Id",而不是"id";
2.用thinkphp的where条件的时候,如果是用字符串的形式,应该是不区分大小写的,所以我把Id写成id也一样可以,但用数组的形成的时候是区分大小写的,大小写写错了就会出问题了。

另外,谢谢各位的回答。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn