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

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

问题描述

是否可以使用 cfquery 执行 2 个插入或更新语句?

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

如果是怎么办?

如果不是,在 Coldfusion 中执行多个查询的最佳方式是什么,只打开一个与 DB 的连接.

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

我认为每次调用 cfquery 时,我们都会打开新的连接数据库

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.

我相信,从一开始,ColdFusion 8 数据源就被设置为一次只运行一个查询,因为存在 SQL 注入问题.要更改此设置,您需要使用连接字符串进行修改.

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.

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

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>

始终,始终对用户提交的值使用 cfqueryparam.

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

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

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