如何在经典 ASP 上进行参数化 SQL 查询? [英] How to make a parametrized SQL Query on Classic ASP?

查看:27
本文介绍了如何在经典 ASP 上进行参数化 SQL 查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我在 VBscript 中使用 Classic ASP 执行参数化 SQL 查询的最简单方法吗?

Can someone show me the simplest way of perform a parametrized SQL query using Classic ASP in VBscript?

最好是可编译的示例.

推荐答案

使用 adodb.command 对象.

Use the adodb.command object.

with createobject("adodb.command")
    .activeConnection = application("connectionstring")
    .commandText = "select * from sometable where id=?"
    set rs = .execute( ,array(123))
end with

我还建议使用自定义数据库访问对象,而不是直接使用 adodb.这允许您构建更好的 api,提高可测试性并添加用于调试/记录/分析的钩子.其次,您可以使用 class_terminate 事件添加带有隐式回滚的请求范围事务.我们的 db 访问对象提供了以下查询 api

I would also advise to use a custom db access object instead of using adodb directly. This allows you to build a nicer api, improves testability and add hooks for debuging/logging/profiling. Secondly you can add request scoped transactions with implicit rollback's on errors using the class_terminiate event. Oure db access object offers the following query api

call db.execute("update some_table set column=? where id=?", array(value, id))
set rs = db.fetch_rs("select * from some_table where id=?", array(id))
count = db.fetch_scalar("select count(*) from some_table where column > ?", array(value))

这篇关于如何在经典 ASP 上进行参数化 SQL 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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