Home > Backend Development > PHP Tutorial > Invalid parameter number: number of bound variables does not match number of tokens

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

WBOY
Release: 2016-08-08 09:25:40
Original
2916 people have browsed it
	$criteria = new CDbCriteria();
  	$criteria->addCondition("customid = :customid");
  	$criteria->params= array(':customid'=>$customid);
  	if(trim($groupid)!=""){
  		$criteria->addCondition ('groupid' = :groupid);
Copy after login
<pre name="code" class="php"><span style="white-space:pre">		</span>$criteria->params= array(':groupid'=>$groupid);
Copy after login
Copy after login
Copy after login
<span style="white-space:pre">	</span>}
Copy after login
<span style="white-space:pre">	</span>
Copy after login
} When
Copy after login
Copy after login
wrote the query operation of the Yii framework, he kept reporting an error using CDbCriteria:

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

This error means that the conditions you query do not match the number of parameters;

If you look at my code above with confidence, you will find something to the effect It's wrong. If I meet the conditions of goupid, then in the end I will have only one parameter, which is: goupid, and all the parameters: customid =$customid will be overwritten, so the solution is to do it in the goupid conditional statement. Change:

$criteria->params= array(':customid'=>$customid,':groupid'=>$groupid);
Copy after login

Or it would be better to write it this way:

<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;
  	}
Copy after login

The above introduces Invalid parameter number: number of bound variables does not match number of tokens, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template