au3 连接mysql_AU3连接sql数据库源码

本文介绍了如何使用AutoIt(AU3)脚本连接到SQL Server数据库,提供了一段详细的源码示例,展示了如何执行查询和更新操作。在示例中,脚本连接到192.168.1.200服务器上的'school'数据库,执行了查询和更新学生信息的SQL语句。
摘要由CSDN通过智能技术生成

au3作为一个比较高级的批处理(或者说自动化)工具,它也支持连接到数据库的,本人目前只试过sql与普通的.mdb数据库。

下面给出au3连接sql数据库的源码,本例环境为IP地址为192.168.1.200服务器上的sql数据库,数据库名称为school。AU3可以实现远程连接数据库。

数据库用户名:sa ? 密码为空

sql语句为查找数据库school中studentinfo表中cardno=g2.010的学生的信息

将school数据库中studentinfo表中cardno=g2.010的grade列更新为96

$cardno='g2.010'

$server = "192.168.1.200"

$user = "sa" ;数据库用户名sa

$pwd = "" ;用户密码为空

$dbs = "school" ;数据库名称为school

$conn = ObjCreate("ADODB.Connection")

$RS = ObjCreate("ADODB.Recordset")

$conn.Open("driver={SQL Server};server=" & $server & ";uid=" & $user & ";pwd=" & $pwd & ";database=" & $dbs) ;主机名IP192.168.1.200,UID=用户,PWD=密码,database=数据库名

$RS.ActiveConnection = $conn ; 设定RS 是 conn 的集合 重要的部份

;sql语句 查询语句就使用$rs.open("这里写具体的sql语句跟在sql查询分析器里面的写法差不多")

;sql语句

;$RS.open("select name,class from studentinfo where cardno='" & $cardno &"'")

$name = $RS.Fields(0).value ;接收sql返回的第一个name结果

$class = $RS.Fields(1).value ;接收sql返回的第一个class结果

$RS.close ;查询语句写完后记得关闭查询连接

msgbox(0,"sql查询结果","学生姓名:"& $name &" 学生班级:"&$class)

$conn.Execute("update studentinfo set grade=96 where cardno='" & $cardno & "'") ;将school数据库中studentinfo表中cardno=g2.010的grade列更新为96

$conn.Execute("update studentinfo set grade=60 where grade<60")

;所有的update更新操作写法都如同上面的句子(将分数grade小于60的全部更新为60分)

;$conn.Execute语句可以写多条

$conn.close ;这个最后别忘记了

$conn.close; 执行完sql语句后,最后一步记得关闭数据库连接。

在au3中$RS.open多用于有返回值的sql语句。而$conn.Execute则一般用于没有返回值的情况,也可以用来调用存储过程。

在au3中写sql语句时如果语句中有变量(比如本例中的$cardno),需要注意字符型的变量需要在变量前后加单引号符号——? ??‘’

下面是两种写法,如果引号用的不对可能会报错哦,反正注意下就好了。

假如在AU3程序前面定义$cardno=’g2.010′ ?那么就该用下面语句中上面的那个

假如在AU3程序前面定义$cardno=”‘g2.010’” ?那么就该用下面语句中下面的那个

;$RS.open("select name,class from studentinfo where cardno='" & $cardno &"'")

;$RS.open("select name,class from studentinfo where cardno=" & $cardno)

基于互联网精神,在注明出处的前提下本站文章可自由转载!

本文链接:https://ranjuan.cn/au3连接数据库源码/

赞赏

f0097bdaf28ce48eeb096ecb4c063712.png微信赞赏be368440f169aeda239986a3894173af.png支付宝赞赏

au3反编译源码 myAut2Exe - The Open Source AutoIT Script Decompiler 2.9 ======================================================== *New* full support for AutoIT v3.2.6++ :) ... mmh here's what I merely missed in the 'public sources 3.1.0' This program is for studying the 'Compiled' AutoIt3 format. AutoHotKey was developed from AutoIT and so scripts are nearly the same. Drag the compiled *.exe or *.a3x into the AutoIT Script Decompiler textbox. To copy text or to enlarge the log window double click on it. Supported Obfuscators: 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.14 [June 16, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.15 [July 1, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.20 [Sept 8, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.22 [Oct 18, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.24 [Feb 15, 2008]' , 'EncodeIt 2.0' and 'Chr() string encode' Tested with: AutoIT : v3. 3. 0.0 and AutoIT : v2.64. 0.0 and AutoHotKey: v1.0.48.5 The options: =========== 'Force Old Script Type' Grey means auto detect and is the best in most cases. However if auto detection fails or is fooled through modification try to enable/disable this setting 'Don't delete temp files (compressed script)' this will keep *.pak files you may try to unpack manually with'LZSS.exe' as well as *.tok DeTokeniser files, tidy backups and *.tbl (<-Used in van Zande obfucation). If enable it will keep AHK-Scripts as they are and doesn't remove the linebreaks at the beginning Default:OFF 'Verbose LogOutput' When checked you get verbose information when decompiling(DeTokenise) new 3.2.6+ compiled Exe Default:OFF 'Restore Includes' will separated/restore includes. requires ';<AUT2EXE INCLUDE-START' comment to be present in the script to work Default:ON 'Use 'normal' Au3_Signature to find start of script' Will uses the normal 16-byte start signature to detect the start of a
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值