求助大佬们这个问题怎么解决

浏览:908 发布日期:2017/08/13 分类:ThinkPHP5专区
今天用tp更新数据报了数据库的错误。。但是查询都没有出问题
控制器代码:    public function test6()
    {
        $term = ['2015-2016-1','2015-2016-2','2016-2017-1','2016-2017-2'];
        $xxk = db('xuanxiuke')->field('id,课程编号')->select();
        $i=0;
        foreach ($xxk as $k => $v) {
            $data[$i][$term[0]] = db('gradeall')->where('课程编号',$v['课程编号'])->where('获得学期',$term[0])->avg('成绩');
            $data[$i][$term[1]] = db('gradeall')->where('课程编号',$v['课程编号'])->where('获得学期',$term[1])->avg('成绩');
            $data[$i][$term[2]] = db('gradeall')->where('课程编号',$v['课程编号'])->where('获得学期',$term[2])->avg('成绩');
            $data[$i][$term[3]] = db('gradeall')->where('课程编号',$v['课程编号'])->where('获得学期',$term[3])->avg('成绩');
            $data[$i]['id']=$v['id'];var_dump($data);
            db('xuanxiuke')->update($data[$i]);die;
            $i++;
        }
        

        
    }
报错信息:F:\wamp64\www\shoujixinxi\application\index\controller\Index.php:104:
array (size=1)
  0 => 
    array (size=5)
      '2015-2016-1' => float 89.201754385965
      '2015-2016-2' => float 89.164251207729
      '2016-2017-1' => null
      '2016-2017-2' => float 86.8
      'id' => int 1
[10501] PDOException in Connection.php line 451
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
            // 调试结束
            $this->debug(false);

            $this->numRows = $this->PDOStatement->rowCount();
            return $this->numRows;
        } catch (\PDOException $e) {
            if ($this->isBreak($e)) {
                return $this->close()->execute($sql, $bind);
            }
            throw new PDOException($e, $this->config, $this->getLastsql());
        } catch (\Exception $e) {
            if ($this->isBreak($e)) {
                return $this->close()->execute($sql, $bind);
            }
            throw $e;
        }
    }

    /**
Call Stack
in Connection.php line 451
at Connection->execute('UPDATE `xuanxiuke` ...', ['__data__2015-2016-1' => [89.201754385965, 2], '__data__2015-2016-2' => [89.164251207729, 2], '__data__2016-2017-2' => [86.8, 2], ...]) in Query.php line 239
at Query->execute('UPDATE `xuanxiuke` ...', ['__data__2015-2016-1' => [89.201754385965, 2], '__data__2015-2016-2' => [89.164251207729, 2], '__data__2016-2017-2' => [86.8, 2], ...]) in Query.php line 2232
at Query->update(['2015-2016-1' => 89.201754385965, '2015-2016-2' => 89.164251207729, '2016-2017-1' => null, ...]) in Index.php line 105
at Index->test6()
at ReflectionMethod->invokeArgs(object(Index), []) in App.php line 196
at App::invokeMethod([object(Index), 'test6'], []) in App.php line 408
at App::module(['index', 'index', 'test6'], ['app_host' => '', 'app_debug' => true, 'app_trace' => false, ...], true) in App.php line 295
at App::exec(['type' => 'module', 'module' => ['index', 'index', 'test6']], ['app_host' => '', 'app_debug' => true, 'app_trace' => false, ...]) in App.php line 123
at App::run() in start.php line 18
at require('F:\wamp64\www\shouji...') in index.php line 17
Exception Datas
PDO Error Info
SQLSTATE    HY093
Driver Error Code    0
Driver Error Message    
Database Status
Error Code    10501
Error Message    SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
Error SQL    UPDATE `xuanxiuke` SET `2015-2016-1`='89.201754385965',`2015-2016-2`='89.164251207729',`2016-2017-1`=NULL,`2016-2017-2`='86.8' WHERE `id` = 1
Database Config
type    mysql
hostname    127.0.0.1
database    csu
hostport    
dsn    
params    []
charset    utf8
prefix    
debug    true
deploy    0
rw_separate    false
master_num    1
slave_no    
fields_strict    true
result_type    2
resultset_type    array
auto_timestamp    false
datetime_format    Y-m-d H:i:s
sql_explain    false
builder    
query    \think\db\Query
break_reconnect    false
奇怪的是他报错 的sql语句竟然可以成功的在phpmyadmin执行
在mysql控制台也可以执行
这怎么解决各位大佬
最佳答案
评论( 相关
后面还有条评论,点击查看>>