Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date aftersave不';我不能在伊工作_Date_Datetime_Yii - Fatal编程技术网

Date aftersave不';我不能在伊工作

Date aftersave不';我不能在伊工作,date,datetime,yii,Date,Datetime,Yii,在yii中,aftersave不起作用。。。。。。。在tbl1中创建记录后,我需要更新tbl1中的到期日期,即,通过添加tbl2 duration来完成,下面是代码 parent::afterSave(); if ($this->isNewRecord) { $sql1="select sid,createdate from tbl1 where(pid=". $_GET['ppid'] ." and mpid=". $th

在yii中,aftersave不起作用。。。。。。。在tbl1中创建记录后,我需要更新tbl1中的到期日期,即,通过添加tbl2 duration来完成,下面是代码

parent::afterSave();
    if ($this->isNewRecord)
    {
        $sql1="select sid,createdate 
        from tbl1
        where(pid=". $_GET['ppid'] ." and mpid=". $this->mid. ")";
        $edata=Yii::app()->db->createCommand($sql1)->queryRow();


        var_dump($edata);
        $sql2="select duration
        from tbl2
        where ( pid=". $_GET['ppid'] ." and sid=".$edata['sid'].")";

$duration=Yii::app()->db->createCommand($sql2)->queryScalar();

        var_dump($duration);
    //  $expirydate=date('Y-m-d H:i:s', strtotime($edate['createdate']."+ $duration"));
    $expirydate = date("Y-m-d H:i:s", strtotime($edata['createdate'] . " + $duration "));
        var_dump($expirydate);
        $sql="update tbl1 set expirydate=".$expirydate." where ( mpid=" .$this->mid ." and pid=".      $_GET['ppid'].")";
             $connection=Yii::app()->db;
                $command=$connection->createCommand($sql);
                      $tts=$command->execute();
我得到的错误是

  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 '00:00:00 where ( mid=42 and prid=4)' at line 1. The SQL statement executed was: update tbl1 set expirydate=1970-01-01 00:00:00 where ( mid=42 and pid=4) 
试试这个

"update tbl1 set expirydate='".$expirydate."' where 
你需要把你的有效期保留在单引号内

注意:-我在您的
“$expirydate
之前和之后添加了一个

更新 尝试以下更改

$expirydate = date("Y-m-d H:i:s", strtotime("$edata['createdate'] + $duration "));

为什么不为tbl1创建一个模型类呢?这样,您可以将代码限制为$tbl1=tbl1::model()->findByAttributes(数组('pid'=>…,'mpid'=>…)$tbl1->到期日=$tbl1->save();--更干净的是,我确实有tbl1的模型类,问题是我必须在保存记录后更新它,并且要添加的持续时间在另一个tbl2$expirydate=date(“Y-m-d H:i:s”,strotime($edata['createdate']。“+$duration”);它没有获取$edata['createdate']或$duration我不明白为什么,所以我不确定我是否理解,但只要调用activerecord实例上的->refresh()方法从DB重新加载行即可。它存储1970-01-01 00:00:00作为到期日期我要存储$expirydate=date(“Y-m-d H:I:s”,strotime($edata['createdate'](“+$duration”);这样做,我得到了以下错误解析错误:语法错误,意外的T_-ENCAPSED_和_空格,期望T_字符串或T_变量或T_-NUM_字符串inca您发布$edata['createdate']和$duration的值?我认为它没有获取$edata['createdate']我不明白为什么它这么高,但由于aftersave我看不到这些价值。。。