Query Box


Im a new bie,

I want a page where there is a scope to our personalize queries such as "select * from database_table;" .

So I created a page where there is a textArea.

<div class="row">

		<?php echo $form->label($model,'query'); ?>

		<?php echo $form->textArea($model,'query',array('size'=>200,'maxlength'=>500)); ?>


        <div class="row buttons">

		<?php echo CHtml::submitButton('Query'); ?>


In Controller:

Here where I am facing problem. Im reading the variable thru $model->query;

I cannot use findBySql($model->query). I should use dbcriteria. Can anyone give an example how to do it?

Is there any other way possible to solve this challenge????

Thnks :)

If I understand you… the user have to enter the complete SQL query that you want to execute…

First of all… IMO that is too risky because you don’t know what you will execute… and

second… how would the user know what table and what fields it needs ???

Apart from that you can use something like:


$query=... <do whatever you need to check if $query is OK> ...

$command  = Yii::app()->db->createCommand($query);