import csv into mysql via console

Please help, Im new in yii. i required to import csv file into mysql database via command line using yii 1.1

i hv csv file:


name, age, location,

sirin,23,Mannarkkad/India

abdul majid,23,Mannarkkad/India

boby,25,Heringen / Helme

this is my action:


<?php


class ImportCommand extends CConsoleCommand

{

    public function actionImportCSV()

        {

           if (($handle = fopen(Yii::app()->baseUrl.'/test.csv', 'r')) !== false) {

            // $i = 0;

            while (($row = fgetcsv($handle, 1000, ",")) !== false) {

                $model=TblUser::model()->findAll();

                $model = new TblUser();

                // $model->id = $row[0];

                $model->name = $row[0];

                $model->age = $row[1];

                $model->location = $row[2];

                if ($model->validate()) {

                    $model->save();

                } else {

                    //... code If an error in the preservation


                }

            }

            fclose($handle);

        }

    }

}

this is my model:


<?php

class TblUser extends CActiveRecord

{

    /**

     * @return string the associated database table name

     */

    public function tableName()

    {

        return 'tbl_user';

    }


    /**

     * @return array validation rules for model attributes.

     */

    public function rules()

    {


        return array(

            array('name, age, location', 'required'),

            array('age', 'numerical', 'integerOnly'=>true),

            array('name, location', 'length', 'max'=>100),


            array('name, age, location', 'safe', 'on'=>'search'),

        );

    }


    /**

     * @return array relational rules.

     */

    public function relations()

    {

        // NOTE: you may need to adjust the relation name and the related

        // class name for the relations automatically generated below.

        return array(

        );

    }


    /**

     * @return array customized attribute labels (name=>label)

     */

    public function attributeLabels()

    {

        return array(

            'name' => 'Name',

            'age' => 'Age',

            'location' => 'Location',

        );

    }


    /**

     * Retrieves a list of models based on the current search/filter conditions.

     *

     * Typical usecase:

     * - Initialize the model fields with values from filter form.

     * - Execute this method to get CActiveDataProvider instance which will filter

     * models according to data in model fields.

     * - Pass data provider to CGridView, CListView or any similar widget.

     *

     * @return CActiveDataProvider the data provider that can return the models

     * based on the search/filter conditions.

     */

    public function search()

    {

        // @todo Please modify the following code to remove attributes that should not be searched.


        $criteria=new CDbCriteria;


        $criteria->compare('name',$this->name,true);

        $criteria->compare('age',$this->age);

        $criteria->compare('location',$this->location,true);


        return new CActiveDataProvider($this, array(

            'criteria'=>$criteria,

        ));

    }


    /**

     * Returns the static model of the specified AR class.

     * Please note that you should have this exact method in all your CActiveRecord descendants!

     * @param string $className active record class name.

     * @return TblUser the static model class

     */

    public static function model($className=__CLASS__)

    {

        return parent::model($className);

    }

}

error message:


exception 'CException' with message 'Property "TblUser.name" is not defined.' in C:\xampp\htdocs\yii\framework\base\CComponent.php:183

Stack trace:

#0 C:\xampp\htdocs\yii\framework\db\ar\CActiveRecord.php(159): CComponent->__set('name', 'name')

#1 C:\xampp\htdocs\mpng2\protected\commands\ImportCommand.php(13): CActiveRecord->__set('name', 'name')

#2 [internal function]: ImportCommand->actionImportCSV()

#3 C:\xampp\htdocs\yii\framework\console\CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(ImportCommand), Array)

#4 C:\xampp\htdocs\yii\framework\console\CConsoleCommandRunner.php(67): CConsoleCommand->run(Array)

#5 C:\xampp\htdocs\yii\framework\console\CConsoleApplication.php(91): CConsoleCommandRunner->run(Array)

#6 C:\xampp\htdocs\yii\framework\base\CApplication.php(169): CConsoleApplication->processRequest()

#7 C:\xampp\htdocs\yii\framework\yiic.php(33): CApplication->run()

#8 C:\xampp\htdocs\mpng2\protected\yiic.php(7): require_once('C:\xampp\htdocs...')

#9 {main}

Please … provide any idea to fix this?

thanks!