Help with my query, return error

Hi,

All i do is a query and bind params but returns an CDbException don’t know why…

In my debug all seens fine

heres the error:

The debug output:

My Code:


	private function myGetItemsWhere($dados)

	{

		$whereQuery = '';

		if(!$dados || !is_array($dados))

		{

			return '';	

		}

		foreach($dados as $key => $value)

		{

			if(empty($value)) continue;

			$whereQuery .= " AND {$key} LIKE :{$key}";


		}

		return $whereQuery;

	}

	

	private function myGetItemsPrepareWhere($dados, &$command)

	{

		if(!$dados || !is_array($dados))

		{

			return;	

		}

		echo '<br>Bind params:<br>';

		foreach($dados as $key => $value)

		{

			if(empty($value)) continue;

			$value = "%{$value},%";

			echo ":{$key} -> $value<br>";

			$command->bindParam(":{key}",$value,PDO::PARAM_STR);	

		}

	}

	

	private function myGetItemsCount($dados)

	{

		if(!$this->aleatorio)

			return -1;

		$query = 'SELECT COUNT(*) FROM item WHERE appid = '.$this->id.$this->myGetItemsWhere($dados);

		$command = Yii::app()->db->createCommand($query);

		echo 'QUERY: '.$query.'<br>';

		//$command->bindParam(":appid",$this->id,PDO::PARAM_INT);	

		$this->myGetItemsPrepareWhere($dados, $command);exit();

		return $command->queryScalar();

	}

	

	public function myGetItemsFromDados($dados)

	{

		echo $this->myGetItemsCount($dados);

	}

Thanks

I think you have a sintax error here:


$command->bindParam(":{key}",$value,PDO::PARAM_STR);

should be


$command->bindParam(":{$key}",$value,PDO::PARAM_STR);    

so key should be $key.

hope this helps

Bettor

Oh yes, my bad

Sometimes wrong code seens to be correct

Thanks!