Yii Framework Forum: CDbCommand failed to execute the SQL statement - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CDbCommand failed to execute the SQL statement SQLSTATE[HY090]: [Microsoft][ODBC Driver Manager] Invalid string or bu Rate Topic: ***** 1 Votes

#1 User is offline   Mirza Khurram 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 14-June 16
  • Location:Jeddah

Posted 14 June 2016 - 08:54 AM

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>


But Clicking On Save Button getting this error on line below...

CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement: SQLSTATE[HY090]: [Microsoft][ODBC Driver Manager] Invalid string or buffer length. The SQL statement executed was:


Error is on this line

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

0

#2 User is offline   Paul G. 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 24-April 09
  • Location:Tel Aviv, Israel

Posted 26 October 2016 - 06:09 AM

Try changing the line with error to this:

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


Yii fan from Norway
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users