Hi, i need to use a sql sentence in a model function. In models->user.php i made a new function so i can use it later.
public function search_friend()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$connectedUserID = Yii::app()->user->getState('idRedComercio');
$idUsuario = '0';
$idRedComercio = '0';
$idReferido = '0';
mysql_connect('localhost', 'root', '123456');
mysql_select_db('c1redcomercio');
$query = sprintf("SELECT rc_usuario.*, rc_referidos.*
FROM rc_referidos
INNER JOIN rc_usuario ON rc_usuario.idUsuario = rc_referidos.idReferido
WHERE rc_referidos.idRedComercio = '$connectedUserID'",
mysql_real_escape_string($idUsuario),
mysql_real_escape_string($idRedComercio),
mysql_real_escape_string($idReferido));
$data = mysql_query($query);
$criteria=new CDbCriteria;
while ($criteria = mysql_fetch_assoc($data)) {
$criteria->compare('idUsuario',$this->idUsuario);
$criteria->compare('idRol',$this->idRol);
//$criteria->with=array('idRol0');
//$criteria->addSearchCondition('LOWER(idRol0.desRol)', strtolower($this->idRol));
$criteria->compare('idRedComercio',$this->idRedComercio);
$criteria->compare('nombre',$this->nombre,true);
$criteria->compare('apellidos',$this->apellidos,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('web',$this->web,true);
$criteria->order='idRedComercio';
return new CActiveDataProvider($this, array('criteria'=>$criteria,));
}
}
But i keep getting "Fatal error: Call to a member function compare() on a non-object in C:\xampp\htdocs\protected\models\Usuario.php on line 257"
How can i fix that?
Thanks!