Invalid parameter number: number of bound variables does not match number of tokens

php中文网
发布: 2016-08-08 09:25:40
原创
3242人浏览过

	$criteria = new CDbCriteria();
  	$criteria->addCondition("customid = :customid");
  	$criteria->params= array(':customid'=>$customid);
  	if(trim($groupid)!=""){
  		$criteria->addCondition ('groupid' = :groupid);
登录后复制
<pre name="code" class="php"><span style="white-space:pre">		</span>$criteria->params= array(':groupid'=>$groupid);
登录后复制
登录后复制
<span style="white-space:pre">	</span>}
登录后复制
<span style="white-space:pre">	</span>
登录后复制
}
登录后复制
在写Yii框架的查询操作时,使用CDbCriteria一直在报一个错:

invalid parameter number: number of bound variables does not match number of tokens.

这个报错的意思是你查询的条件和参数个数不相符;

如果自信观察下我上面的代码,会发现有个大意的错误了的,加入我符合goupid的条件,那么最终我的参数就只有一个,就是 :goupid,而全线的:customid =$customid就会被覆盖了,所以解决的办法就是在goupid条件语句里面做个更改:

The Book of Ruby
The Book of Ruby

无论你是新学习编程,或刚接触Ruby,这本书可以引导你用独特和优雅的语言体验真实真实的软件开发。 Ruby is famous for being easy to learn, but most users only scratch the surface of what it can do. While other books focus on Ruby’s trendier features, The Book of Ruby reveals the secret inner wo

The Book of Ruby0
查看详情 The Book of Ruby
$criteria->params= array(':customid'=>$customid,':groupid'=>$groupid);
登录后复制

或者使用这种写法会更好:

<span style="white-space:pre">	</span>$criteria = new CDbCriteria();
  	$criteria->addCondition("customid = :customid");
  	$criteria->params[':customid'] = $customid;
  	if(trim($groupid)!=""){
  		$criteria->addCondition ("groupid = :groupid");
  		$criteria->params[':groupid'] = $groupid;
  	}
登录后复制

以上就介绍了Invalid parameter number: number of bound variables does not match number of tokens,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号