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