Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

ThinkPHP5.1x数据查询表达式报错,和5.0x版的有区别?

原来5.0x版本的原来可以这么写,没有报错并且正常查询到数据!

$ids = array(
    0 => 121,
    1 => 125,
    2 => 135
);
$where=[];
$where['site_id'] = ['in',$ids];
$data = Db::name('site')->where($where)->count();

但是在5.1x版报 sql语句错误,具体错误代码如下!

SQLSTATE[42000]: Syntax error or access violation: 1064 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

问:在5.1x版本中这个数组查询表达式应该怎么写?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

楼上正解 或者 使用

$data = Db::name('site')->whereIn($ids)->count();
$ids = array(
    0 => 121,
    1 => 125,
    2 => 135
);
$where=[];
array_push($where, ["id", "In", $ids]);
$data = Db::name('site')->where($where)->count();

个人更喜欢下面这种


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...