Newbie question: ActiveRecord returning table schema instead of data

Hi there,

Since my Gii tool is unable to generate model for my table, I have to write it myself. And either I’m doing something wrong with accessing such model or I made a mistake in declaring it.

I used existing, working model from another app and MySQL database and only changed table name and table columns names, so at least in theory there should be no error in model definition. At least in theory…

Once again I read through "Active Record: Reading Record" and used as simple approach as it can be, i.e.:


$users = Users::model()->findAll();


foreach($users as $user)

{

   	print_r($user);

}

I was supposing to see all my records in the table for which Users model was created (all my users) but instead of that I saw some garbage that looks like table schema or ActiveRecord definition:

994

oracle_db_garbage.png

I changed to DAO approach:


$sql = 'SELECT * FROM WWW_USERS';

$connection = Yii::app()->db;

$command = $connection->createCommand($sql);

$dataReader = $command->query();

$rows = $dataReader->readAll();


print_r($rows);

And immediately got supposed results - i.e. list of all records in DB table.

Has anyone got any idea, what am I doing wrong, that AR approach doesn’t seems to be working, while DAO works like a charm?

You are using print_r($user)… that actualy displays the object data…

just use echo $user->username… .for example

Did this approach before using print_r and before posting. Got error saying that Property Users.login is undefined. Only now I realised, that I’m dealing with Oracle, where column names are case-sensitive, therefore I have to use $user->LOGIN. Aaaarrrg! :confused:

In fact, I used print_r to see, why do I get above error instead of data? But I wasn’t aware that this is normal PHP behaviour and it is returning object info instead of object itself.

EoT