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
WBOYOriginal
2016-08-08 09:25:402878browse
	$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>
} When
 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);

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;
  	}

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.

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