Parameter Binding Problem

EDIT: Mods, feel free to delete this topic.

I’m having trouble getting authentication working.

In the file: protected/components/UserIdentity.php

I have the following line:

$user = User::model()->findByAttributes(array('email'=>$this->username));

This leads to the creation of this Criteria Object, which seems about right to me:

[indent]CDbCriteria Object ( [select] => * [distinct] => [condition] => [params] => Array ( [:yp0] => ) [limit] => -1 [offset] => -1 [order] => [group] => [join] => [having] => [with] => [alias] => [together] => [index] => [_e:CComponent:private] => [_m:CComponent:private] => ) [/indent]

The only trouble is that the user in the database (with “email” value “”) is not getting found because the query being performed (according to the log) is:

[indent]13:28:15.102648 trace system.db.CDbCommand

Querying SQL: SELECT * FROM mydatabase.user t WHERE LIMIT 1[/indent]

There are two problems here that I can see:

  1. the “AS” is missing before the table name alias

  2. the parameters are not getting bound

Any ideas about what might be going on? (Using Yii version 1.1.5, Apache 2, PHP 5.3, Firefox 3.6)

(I’m guessing I haven’t configured something right, but then the database driven sessions are working properly…)

Hi and welcome,

your assumptions 1) and 2) are not quite right. Where you think AS is missing? And about 2): Try to set enableParamLogging true in your db component configuration:


    'connectionString'  =>'mysql:host=bla;dbname=blu',

    'username'          => 'user',

    'password'          => 'secret',

    'enableParamLogging'  => true,        // Log SQL parameters

I found quite weird the fact that username and email are the same, is that correct?

$user = User::model()->findByAttributes(array('email'=>$this->username)); // looking for username in email field

I don’t know but this query seems too easy for Yii to fail. I would double check what I’ve done carefully in my code and do as Mike said, enable parameter Log, Yii wont fail in such thing.

Hi Mike,

Thanks for the welcome and the advice.

You’re quite right about my wrong assumptions:

  1. No “AS” required (I’d always thought you needed an “AS” between the table name and its alias

  2. The binding was working all right (as I saw once I enabled the parameter logging).

I still haven’t figured out what I’m doing wrong, but it’s certainly me not Yii.