lundi 4 juillet 2016

CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement

I am using Yii with PHP and with Sql Server 2008 R2. Can anyone tell me where is the problem ?

public function actionUpdate($id)
    {
        $model=$this->loadModel($id);

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if(isset($_POST['Hold']))
        {
            $model->attributes=$_POST['Hold'];
            $model->startTimeHour=cc("select code from Lookup where name='$model->startTime' and type='starttime'")->queryScalar();
            if($model->save())
                $this->redirect(array('view','id'=>$model->id));
        }

        $this->render('update',array(
            'model'=>$model,
        ));
    }

Model $model->startTime Holds values in Dropdown. Here is the code of that as well.

<div class="control-group">
        <label class="control-label"><?php echo $form->labelEx($model,'startTime'); ?></label>
        <div class="controls">
            <?php echo $form->dropDownList($model,'startTime',$this->_startTime); ?>
            <span class="help-inline"><?php echo $form->error($model,'startTime'); ?></span>
        </div>
    </div>

Error on this Line of actionUpdate($id)

$model->startTimeHour=cc("select code from Lookup where name='$model->startTime' and type='starttime'")->queryScalar();

Error message:

CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement

Aucun commentaire:

Enregistrer un commentaire