如何在ColdFusion中使用CFQuery执行2个或更多的insert语句? [英] How to Execute 2 or more insert statements using CFQuery in coldfusion?

查看:134
本文介绍了如何在ColdFusion中使用CFQuery执行2个或更多的insert语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 cfquery


执行2插入或更新语句如果是, p>

如果没有,在Coldfusion中执行多个查询的最佳方法是只打开一个到DB的连接。



我认为每次我们调用 cfquery 我们正在打开新的连接DB

解决方案

在数据源设置中,您可以通过维护连接设置来确定是否保持连接打开。



从ColdFusion 8数据源开始由于担心SQL注入,因此一次只能运行一个查询。要更改此设置,您需要使用连接字符串进行修改。



最好的办法是打开维护连接,如果需要使用cftransaction:

 < cftransaction> 
< cfquery name =insdatasource =dsn>
insert into table1 values(< cfqueryparam value =#url.x#>)
< / cfquery>
< cfquery name =insdatasource =dsn>
insert into table2 values(< cfqueryparam value =#url.x#>)
< / cfquery>
< / cftransaction>

始终对用户提交的值使用cfqueryparam。


Is it possible to Execute 2 insert or Update Statements using cfquery?

If yes how?

if no, what is the best way to execute multiple queries in Coldfusion, by opening only one Connection to DB.

I think every time we call cfquery we are opening new connection DB

解决方案

Within the data source settings you can tell it whether to keep connections open or not with the Maintain Connections setting.

Starting with, I believe, ColdFusion 8 datasources are set up to run only one query at a time due to concerns with SQL injection. To change this you would need to modify with the connection string.

Your best bet is to turn on Maintain Connections and if needed use cftransaction:

<cftransaction>
<cfquery name="ins" datasource="dsn">
insert into table1 values(<cfqueryparam value="#url.x#">)
</cfquery>
<cfquery name="ins" datasource="dsn">
insert into table2 values(<cfqueryparam value="#url.x#">)
</cfquery>
</cftransaction>

And always, always use cfqueryparam for values submitted by users.

这篇关于如何在ColdFusion中使用CFQuery执行2个或更多的insert语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆