2015-06-22 25 views
1

我收到此错误时PARAMS未发现:的ColdFusion 9,采用CFSCRIPT查询

参数“USER_ID和league_id”不是在参数列表中找到指定的

我在路过他们,我可以在放在函数内部的转储中查看它们。

这里是怎么回事在什么...

ac = { 
    league_id = 1 
    ,user_id = 3 
    ,score1 = 14 
    ,score2 = 10 
}; 

这是引发错误转储....

writedump(Game.saveGame(argumentcollection = ac)); 

这里是Game.saveGame功能

public any function saveGame(required numeric league_id, required numeric user_id, required numeric score1, required numeric score2) { 

    // writeDump(var=arguments); // this dump shows league_id & user_id... 
    var sql  = ''; 
    var tmp  = ''; 
    var r  = ''; 
    var q  = new query(); 

     q.setDatasource(this.dsn); 

     q.addParam(
       name = 'league_id' 
       ,value = '#val(arguments.league_id)#' 
       ,cfsqltype = 'CF_SQL_BIGINT' 
      ); 
     q.addParam(
       name = 'user_id' 
       ,value = '#val(arguments.user_id)#' 
       ,cfsqltype = 'CF_SQL_BIGINT' 
      ); 
     q.addParam(
       name = 'score1' 
       ,value = '#val(arguments.score1)#' 
       ,cfsqltype = 'CF_SQL_SMALLINT' 
      ); 
     q.addParam(
       name = 'score2' 
       ,value = '#val(arguments.score2)#' 
       ,cfsqltype = 'CF_SQL_SMALLINT' 
      ); 

     sql = 'INSERT INTO 
       games 
       (
        user_id 
        ,league_id 
        ,score1 
        ,score2 
       ) 
      VALUES 
       (
        :user_id 
        ,:league_id 
        ,:score1 
        ,:score2 
       ) 
     '; 

     tmp = q.execute(sql = sql); 

     r = tmp.getPrefix(q); 

     q.clearParams(); 

    return r; 

} 

这是一些问题的历史 - 我在本地写这篇文章,我的系统运行CF 11 .2 - 一切工作正常...但是,我不得不将它托管在CF 9.02服务器上,那就是当这个错误出现时 - 我不能在我的系统上重新创建它,但我确实记得以前看到过这个错误,但是对于我的生活,我不能找到我是如何解决它然后....

任何帮助或见解表示赞赏。

其他PARAMS 的Windows服务器,MySQL 5.5,Apache 2.2的

+0

我看不出有什么不对您的代码,但你可以也许会清理一些东西,不需要单独设置每个“属性”:http://blog.adamcameron.me/2014/01/using-querycfc-doesnt-have-to-be-drama.html –

+0

Thx Adam - 我会试试看,让你知道 - 完全赞赏'更简洁的语法。 – jpmyob

回答

1

亚当写道:

I can't spot what's wrong with your code, but you could perhaps clean things up a bit. There's no need to set each "property" on the query separately: blog.adamcameron.me/2014/01/

继序PARAM,而不是命名PARAM,过往则params的阵列中的冷凝格式,解决了我的问题。

我可能会玩的名称属性,看看它是否,正是..或者我可能只是作为一个解决方案来处理。

现在,要改变我所有的脚本查询!!!!! (祝他的文章提出了对谷歌的时候我一直在寻找进入query.cfc语法:(

感谢一大堆亚当!

+0

很酷。很高兴帮助。 –