Cdbexception Error Using Giix Generators


I recently installed Giix, i’ve never used it before, I have some small sample data in a few tables. I was just clicking through related information, when I went to create another record in a table through Yii. I got the following error that I wondered if anyone could help me with. I have not touched any of the code myself it is all purely generated from Giix and i’ve even regenerated what I thought the problem model/controller was and it still fails.

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option FROM `display_option` `t`' at line 1. The SQL statement executed was: SELECT id, option FROM `display_option` `t`

 C:\xampp\htdocs\Giix\protected\extensions\giix-components\GxActiveRecord.php(248): CActiveRecord->findAll(CDbCriteria)

       if (!is_array($attributes))

244                 $attributes = array($attributes);

245             $attributes = array_merge($pks, $attributes);

246         }

247         $criteria->select = $attributes;

248         return parent::findAll($criteria); // error line

249     }


251     /**

252      * Extracts and returns only the primary keys values from each model.

253      * @param GxActiveRecord|array $model A model or an array of models.**/

// And also

 C:\xampp\htdocs\Giix\protected\views\Item\_form.php(68): GxActiveRecord->findAllAttributes(null, true)

        <?php echo $form->dropDownList($model, 'display_options', GxHtml::listDataEx(DisplayOption::model()->findAllAttributes(null, true))); ?> // error line 

Do you need anything more of the stack?

This occurs when I’m looking at my Item/create or Item/update model/action. I’m guessing (and it is only a guess) it must be some kind of error within my DB structure taht causes Yii to get unhappy or some conflict within Giix: I wasn’t sure where to post this, if it needs to be moved to extensions then please do so and sorry. I’ll post the two DB structures

I have created a new app and used standard Gii and all the create/admin/update functions are available to me within the Model that was throwing the error using Giix.

Item Table

  ### Rest of command

  `display_options` int(3) unsigned NOT NULL,

 ### More commands 

  KEY `fk_display_option` (`display_options`)


display_option table

  `id` int(3) unsigned NOT NULL AUTO_INCREMENT,

  `option` varchar(45) NOT NULL,

  PRIMARY KEY (`id`)


If somebody could help me out that would be great :)

I’m at a bit of a loss as this is just from the Gixx generated code.

Thanks in advance


Hi Jonny,

It seems that option is a reserved word for MySQL.

Gii isn’t failing probably because the column name is being quoted on the generated query or (most probably) it is selecting all columns with *.

It is probably a bug in giix.

To work around it, you can change the line 68 in _form.php to:

<?php echo $form->dropDownList($model, 'display_options', GxHtml::listDataEx(DisplayOption::model()->findAllAttributes('`option`', true))); ?>

What I’m doing here is replacing the automatic use of the representing column (see GxActiveRecord::findAllAttributes code) for the column name. The downside is that if your representing column changes, you’ll have to update it on hte view.

Please let me know whether it works.

Thanks for reporting it!

Hi Rodrigo,

Thanks for looking at this for me. Your work around did work. I actually decided to make the changes to my DB Schema and reupload it and all models/actions seem to work great.

Thanks for taking the time to sort this for me.

Jonathon :D

No problem, Jonny! I hope that giix is being useful to you.