ahk连接数据库

a := new adodb
a.open("DSN=testdb;UID=thinkai;PWD=password;") ;到DSN里面配置了用户名密码则UID PWD不用配置。
ret := a.GetTable("select getdate()")
MsgBox % ret.1.1
 
class adodb
{
    ;static conn
 
    __New() ;新建
    {
    this.conn:= ComObjCreate("ADODB.connection") ;初始化COM
    }
 
    open(connect_str) ;打开文件
    {
        try
            this.conn.Open(connect_str)
        catch e
            return e.Message
    }
 
    close() ;关闭文件
    {
        this.conn.Close()
    }
 
    GetTable(sql)
    {
        t := []
        query := this.conn.Execute(sql)
        if RegExMatch(sql,"i)^select*")
        {
            try
            {
                fetchedArray := query.GetRows() ;取出数据(二维数组)
                colSize := fetchedArray.MaxIndex(1) + 1 ;列最大值 tips:从0开始 所以要+1
                rowSize := fetchedArray.MaxIndex(2) + 1 ;行最大值 tips:从0开始 所以要+1
                loop, % rowSize
                {
                    i := (y := A_index) - 1
                    t[y] := []
                    loop, % colSize
                    {
                        j := (x := A_index) - 1
                        t[y][x] := fetchedArray[j,i] ;取出二维数组内值
                    }
                }
            }
            query.Close()
            return t
        }
    }
}

给TA捐赠
共{{data.count}}人
人已捐赠
其他教程

AHK调试工具

2020-3-21 1:43:00

其他案例

ahk抓抓工具

2020-3-26 13:40:25

个人中心
购物车
优惠劵
有新私信 私信列表
搜索