微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ColdFusion:尝试在CFScript中查询数据库

我的老板要我使用cfscript代替标签进行数据库交互.有人知道任何好的教程吗?我购买了Adobe ColdFusion应用程序开发书,第2卷.但它在脚本编写方面没有太多内容.我做了谷歌并发现了 this site,但它没有解释太多.

有没有人知道有关访问CFScript数据库的任何好教程?

基本上我必须将以下内容转换为使用CFScript:

<cfquery name="drafts" datasource="ICEchat">
    SELECT * from Messages where Istemp=1 and LinkA=#FORM.LinkA# and LinkB=#FORM.LinkA#
</cfquery>
<cfif drafts.recordcount GT '0'>
    <cfquery name="Attachments" datasource="ICEchat">
        SELECT * FROM Attachments where id=2
    </cfquery>
    { Message:"<cfoutput query="drafts">#Message#</cfoutput>",Attachments:[<cfoutput query="attachments">
        "#url#"<cfif attachments.currentRow LT attachments.recordcount>,</cfif>
    </cfoutput>]}
<cfelse>
    <cfquery name="addrecord" datasource="ICEchat">
        INSERT INTO Messages 
        VALUES(1,1,' ',1)
    </cfquery>
    { Message:"NA",Attachments:[]}
</cfif>

解决方法

从谷歌 4th link上的“cfscript查询教程”:
<CFSCRIPT>
    myQry = new Query(); // new query object     
    myQry.setsql("select bookid,title,genre from app.books where bookid = :bookid"); //set query
    myQry.addParam(name="bookid",value="5",CFsqlTYPE="CF_sql_INTEGER"); // add query param
    qryRes = myQry.execute(); // execute query
    writedump(qryRes.getResult().recordcount,true); // get resultcount
    writedump(qryRes.getResult(),false); // dump result
    writeoutput('<BR>');
</CFSCRIPT>

那应该告诉你需要知道的一切.

此外,你真的不应该手动创建JSON,无论它多么简单.使用serializeJson().

原文地址:https://www.jb51.cc/mssql/79068.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐