source := "src.xls" ;源文件
target := "[a].[dbo].[test_table]" ;数据库目标表
has_create_tab := 0 ;是否已创建表
xlsdb := new exceldb() ;创建excel adodb连接,获取数据表信息
xlsdb.open(source)
sheet := xlsdb.GetTableInfo()
;数据库连接
conn := ComObjCreate("ADODB.connection")
conn.Open("driver={SQL Server};server=192.168.8.2;uid=thinkai;pwd=02EdDd68F5CC83__;database=a") ;打开连接
;遍历有效sheet
for k,v in sheet
{
fields := v
if !has_create_tab ;尝试创建表
{
f := ""
for x,y in v
f .= f ? ",[" y "] nvarchar(255) NULL" : "[" y "] nvarchar(255) NULL"
try
conn.Execute("CREATE TABLE " target " (" f ");")
}
field := "" ;生成字段串 注意表格里面的字段名称应和数据库中的字段一致
for x,y in v
field .= field ? ",[" y "]" : "[" y "]"
tmp_result := xlsdb.GetTable("SELECT * FROM [" (InStr(k,"$") ? k : k "$") "];") ;获取单个sheet的全部数据
for row,vaules in tmp_result
{
tmp_str := ""
for k,v in vaules
tmp_str .= tmp_str ? ",'" v "'" : "'" v "'"
conn.Execute("INSERT INTO " target " VALUES (" tmp_str ")") ;插入语句
}
}
MsgBox, OK
getto(str){
o := []
Loop, Parse, str, `n, `r
{
IfInString, A_LoopField, `t
{
t := StrSplit(A_LoopField,"`t")
o[t[1]] := t[2]
}
}
return o
}
class exceldb
{
;static conn
__New() ;新建
{
this.conn:= ComObjCreate("ADODB.connection") ;初始化COM
}
open(file) ;打开文件
{
IfExist % file
this.conn.Open("Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" file) ;打开连接
;this.conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=Yes';Data Source=" file) ;打开连接 2003方式
}
close() ;关闭文件
{
this.conn.Close()
}
GetTableInfo() ;获取所有Sheet及字段信息
{
;通过OpenSchema方法获取表信息
rs := this.conn.OpenSchema(20) ;SchemaEnum 参考 http://www.w3school.com.cn/ado/app_schemaenum.asp
t := []
rs.MoveFirst()
while !rs.EOF
{
t_name := RegExReplace(rs.("TABLE_NAME").value,"^'*(.*)\$'*$","$1")
q := this.conn.Execute("select top 1 * from [" t_name "$]")
if (q.Fields(0).Name="F1" && q.Fields.Count=1) ;排除空表格
{
rs.MoveNext()
continue
}
t[t_name] := []
for field in q.Fields ;获取按顺序排列的字段
t[t_name].insert(field.Name)
q.close()
rs.MoveNext()
}
return t
}
GetTable(sql)
{
t := []
query := this.conn.Execute(sql)
if RegExMatch(sql,"i)^select*")
{
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
}
}
}
本人写来单位自用的一个呼叫中心外呼的一个提取/提交数据工具,po出来仅供交流学习之用。

php接口(UTF-8):
<?php
$c = new PDO( "sqlsrv:server=(local); Database = ", "username", "password", array(PDO::SQLSRV_ATTR_DIRECT_QUERY => true));
if (isset($_GET['str'])){
$str_obj = explode(";",urldecode($_GET['str']));
$str = $str_obj[0];
$token = substr($str,(strlen($str)-12),12);
if ($token=="))))"){
if (isset($_GET['o'])){
if ($_GET['o']==1){
echo qt((substr($str,0,(strlen($str)-12))));
}else if ($_GET['o']==2){
echo get_rowcount((substr($str,0,(strlen($str)-12))));
}
}else{
echo query((substr($str,0,(strlen($str)-12))));
}
}else{
echo "Error token!";
}
}
function get_rowcount($query){
global $c;
$stmt = $c->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->execute();
global $rowcount;
$rowcount=NULL;
$rowcount = $stmt->rowCount();
return $rowcount;
}
function query($query){
global $c;
$stmt = $c->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->execute();
global $rowcount;
$rowcount=NULL;
$rowcount = $stmt->rowCount();
if(stripos($query, 'update') !== false){
return "UP".$rowcount;
}elseif(stripos($query, 'delete') !== false){
return "DE".$rowcount;
}elseif(stripos($query, 'insert') !== false){
return "IN".$rowcount;
}else{
$content=NULL;
if( $stmt->rowCount() == 0){
return "";
}else{
while ( $row = $stmt->fetch( PDO::FETCH_NUM ) ){
for($i = 0; $i < $stmt->columnCount(); $i++)
{
$type=gettype($row[$i]);
if ($type=="object"){
$var=$row[$i];
$time=str_replace("T"," ",$var->format(DateTime::ISO8601));
$time=substr($time,0,19);
$time=$time.".000";
$content=$content.$time.",";
}else{
$ctmp=str_replace(",",",",$row[$i]);
$content=$content.$ctmp.",";
}
}
$content=$content."\n";
}
$content=str_replace(",\n","\n",$content);
return $content;
}
}
}
function qt($query){
global $c;
$stmt = $c->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->execute();
global $rowcount;
$rowcount=NULL;
$rowcount = $stmt->rowCount();
if(stripos($query, 'update') !== false){
return "UP".$rowcount;
}elseif(stripos($query, 'delete') !== false){
return "DE".$rowcount;
}elseif(stripos($query, 'insert') !== false){
return "IN".$rowcount;
}else{
$content=NULL;
if( $stmt->rowCount() == 0){
return "NO";
}else{
$a = $stmt->fetch( PDO::FETCH_ASSOC);
$Fields = array_keys($a);
global $titles;
$titles=NULL;
for($i = 0; $i < $stmt->columnCount(); $i++)
{
$name=iconv('GB2312','UTF-8',$Fields[$i]);
$titles=$titles."$name,";
}
$titles=$titles."\r\n";
$titles=str_replace(",\r\n","",$titles);
$content = $titles."\r\n";
$stmt->execute();
while ( $row = $stmt->fetch( PDO::FETCH_NUM ) ){
for($i = 0; $i < $stmt->columnCount(); $i++)
{
$type=gettype($row[$i]);
if ($type=="object"){
$var=$row[$i];
$time=str_replace("T"," ",$var->format(DateTime::ISO8601));
$time=substr($time,0,19);
$time=$time.".000";
$content=$content.$time.",";
}else{
$ctmp=str_replace(",",",",$row[$i]);
$content=$content.$ctmp.",";
}
}
$content=$content."\r\n";
}
$content=str_replace(",\r\n","\r\n",$content);
return $content;
}
}
}
?>
数据库结构(三张表):
USE [Database1] GO DROP TABLE [dbo].[增值业务目标客户] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[增值业务目标客户]( [地区] [nvarchar](50) NOT NULL, [手机号码] [nvarchar](11) NOT NULL, [外呼业务] [nvarchar](50) NOT NULL, [语种] [nvarchar](50) NULL, [导入日期] [date] NULL, [ID] [int] IDENTITY(1,1) NOT NULL, [SID] [int] NULL, [工号] [nvarchar](50) NULL, CONSTRAINT [PK_增值业务] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO DROP TABLE [dbo].[增值业务目标任务] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[增值业务目标任务]( [地区] [nvarchar](50) NOT NULL, [外呼业务] [nvarchar](50) NOT NULL, [语种] [nvarchar](50) NOT NULL, [导入日期] [date] NOT NULL, [locked] [int] NULL, [id] [int] IDENTITY(1,1) NOT NULL ) ON [PRIMARY] GO ALTER TABLE [dbo].[增值业务数据提交] DROP CONSTRAINT [DF_增值业务数据提交_导入时间] GO ALTER TABLE [dbo].[增值业务数据提交] DROP CONSTRAINT [DF_增值业务数据提交_提交日期] GO ALTER TABLE [dbo].[增值业务数据提交] DROP CONSTRAINT [DF_增值业务数据提交_提交单位] GO DROP TABLE [dbo].[增值业务数据提交] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[增值业务数据提交]( [工号] [nvarchar](50) NULL, [姓名] [nvarchar](50) NULL, [外呼日期] [nvarchar](50) NULL, [业务类型] [nvarchar](50) NULL, [地州] [nvarchar](50) NULL, [语种] [nvarchar](50) NULL, [用户号码] [nvarchar](50) NULL, [接通情况] [nvarchar](50) NULL, [备注] [nvarchar](255) NULL, [质检结果] [nvarchar](50) NULL, [质检备注] [nvarchar](50) NULL, [质检人] [nvarchar](50) NULL, [质检时间] [datetime] NULL, [提交单位] [nvarchar](50) NULL, [提交日期] [date] NULL, [ID] [int] IDENTITY(1,1) NOT NULL, [LID] [int] NULL, [导入时间] [datetime] NULL ) ON [PRIMARY] GO ALTER TABLE [dbo].[增值业务数据提交] ADD CONSTRAINT [DF_增值业务数据提交_提交单位] DEFAULT (N'呼叫中心') FOR [提交单位] GO ALTER TABLE [dbo].[增值业务数据提交] ADD CONSTRAINT [DF_增值业务数据提交_提交日期] DEFAULT (CONVERT([date],getdate())) FOR [提交日期] GO ALTER TABLE [dbo].[增值业务数据提交] ADD CONSTRAINT [DF_增值业务数据提交_导入时间] DEFAULT (getdate()) FOR [导入时间] GO
Autohotkey代码(ANSI32):
#SingleInstance force ;单线程
FileEncoding, UTF-8 ;php pdo是utf-8的
FileInstall, 1.bmp, 1.bmp ;打电话的图标
FileInstall, 2.bmp, 2.bmp
;数据库配置信息
host = 135.230.71.1
api = http://%host%/sqlapi.php ;接口url
oldtime = %A_TickCount% ;上次点击时间
;检查连通性
if Not InStr(ping_info := ping(host),"正常")
{
MsgBox, 4112, 网络错误, % ping_info
ExitApp
}
;登陆界面
gui, login:add, text, x0 y0 w60 h20, 工号:
gui, login:add, edit, x60 y0 w200 h20 vuser_id,
gui, login:add, text, x0 y20 w60 h20, 姓名:
gui, login:add, edit, x60 y20 w200 h20 vuser_name,
gui, login:add, text, x0 y40 w60 h20, 语种:
gui, login:add, DropDownList, x60 y40 w200 h60 vuser_lang, 汉语|英语
gui, login:add, button, x0 y60 w260 h20 glogin, 登陆
gui, login:show, , 坐席登陆
gui, login:+AlwaysOnTop
Return
login:
Gui, login:Submit, NoHide
if user_lang=
{
MsgBox, 4112, 错误, 未选择语种!
Return
}
user_id := StrLen(user_id)=3 ? user_id : SubStr(user_id,1,3) ;只保留前三位
user_id := user_id "#" ;添加#
;检查工号是否在数据库内
if (get_1_result("SELECT count(*) FROM [Database1].[dbo].[用户表] where 工号='" user_id "'")>0)
{
gui, login:Destroy
goto, show
}
Else
{
MsgBox, 4112, 错误, 没有此工号!
}
Return
show:
;创建界面
Gui,main:Add,Text,x0 y3 w60 h12,当前任务:
Gui,main:Font,Normal s8 c0x0 Bold,Verdana
Gui,main:Add,Text,x60 y3 w260 h15 vtask_name,
Gui,main:Font
Gui,main:Add,Button,x320 y0 w40 h20 gchoose, 选择
Gui,main:Add,Text,x360 y3 w60 h12,任务信息:
Gui,main:Font,Normal s8 Bold,Verdana
Gui,main:Add,Text,x420 y3 w230 h15 vtask_info,
Gui,main:Font
Gui,main:Add,Text,x0 y23 w60 h12,联系电话:
Gui,main:Font,Normal s9 c0x0 Bold,Verdana
Gui,main:Add,Edit,x60 y20 w120 h20 ReadOnly 1 Border vphone,
Gui,main:Font
Gui,main:Add,Button,x180 y20 w50 h20 gcall,外呼
Gui,main:Add,Text,x230 y23 w60 h12,接通情况:
Gui,main:Add,DropDownList,x290 y20 w200 vcalling_result, 通后挂断|无人接听|成功|关机|无法接通|少数民族|停机|用户考虑|空号|拒绝使用|老人小孩|不是机主
Gui,main:Add,Text,x0 y43 w60 h12,备注:
Gui,main:Add,Edit,x60 y40 w430 h20 vnote,
Gui,main:Add,ListView,x0 y60 w650 h108, 工号|姓名|外呼日期|业务类型|地州|语种|用户号码|接通情况|备注|质检结果|质检备注|质检人|质检时间|提交单位|提交日期|ID|LID|导入时间
Gui,main:Add,Button,x490 y20 w80 h40 gsubmit, 提交
Gui,main:Add,Button,x570 y20 w80 h40 gupdate, 修改
Gui,main:Show,w650 h170 , xx呼叫中心增值业务
Gui,main:+AlwaysOnTop
Gui,main:Default
Gosub, show_lv ;显示当日已拨打电话
Return
submit:
;检查是否频繁提交
if newtime<>
oldtime = %newtime%
newtime = %A_TickCount%
timediff := newtime-oldtime
if timediff < 6000
{
MsgBox, 4144, 提示, 请勿频繁提交,稍后再试!
Return
}
;获取表单
gui, main:submit, NoHide
GuiControl, main:Choose, calling_result, 0
GuiControl, main:, note,
calldate = %A_YYYY%-%A_MM%-%A_DD%
;插入
effect_row := get_rowcount("INSERT INTO [Database1].[dbo].[增值业务数据提交] ([工号],[姓名],[外呼日期],[业务类型],[语种],[地州],[用户号码],[接通情况],[备注],[LID])Values('" user_id "','" user_name "','" calldate "','" business "','" user_lang "','" area "','" phone "','" calling_result "','" note "','" id "')")
;获取刚才插入的id
sid := get_1_result("select top 1 id from [Database1].[dbo].[增值业务数据提交] where 工号='" user_id "' and 外呼日期='" calldate "' and 用户号码='" phone "' order by id desc")
;在目标客户表里添加sid 即提交表里的id
effect_row := get_rowcount("update [Database1].[dbo].[增值业务目标客户] set sid='" sid "' where id='" id "'")
Gosub, show_lv
goto, get_task
Return
update:
;获取单击点中的行
FocusedRowNumber := LV_GetNext(0, "F")
if not FocusedRowNumber
{
MsgBox, 4144, 提示, 您未选择任何当已提交数据!
Return
}
LV_GetText(e_id, FocusedRowNumber, 16)
WinGetPos, x, y, , , xx呼叫中心增值业务
gui, main:Hide
WinHide, xx呼叫中心增值业务
gui, 3:Destroy
gui, 3:add, DropDownList, x0 y0 w200 h600 ve_calling_result, 通后挂断|无人接听|成功|关机|无法接通|少数民族|停机|用户考虑|空号|拒绝使用|老人小孩|不是机主
gui, 3:add, Button, x200 y0 w40 h20 gsubupdate,确定
gui, 3:show, x%x% y%y% , 修改接通情况
Return
subupdate:
GuiControlGet, e_calling_result
;排除没有选择的情况
if e_calling_result <>
{
gui, 3:Destroy
gui, main:show
;更新
effect_row := get_rowcount("update [Database1].[dbo].[增值业务数据提交] set 接通情况='" e_calling_result "' where id='" e_id "'")
}
Return
call:
;在拨打界面网页内直接输入号码并点击拨打
Clipboard = %phone%
WinWait, 客服中心拨打界面
WinActivate, 客服中心拨打界面
error = 1
Loop, 1000
{
ImageSearch, x, y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 1.bmp
if !Errorlevel
{
x+=30
y+=5
MouseClick, Left, %x%, %y%
loop, 20
{
Send, {Delete}{BackSpace}
}
send, ^v
error = 0
Break
}
Sleep, 50
}
if error = 0
{
Loop, 1000
{
ImageSearch, x, y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 2.bmp
if !Errorlevel
{
x+=10
y+=5
MouseClick, Left, %x%, %y%
Break
}
Sleep, 50
}
}
Return
show_lv:
;删除现有
LV_Delete()
;获取当日该工号外呼提交数据倒序前20项
result := get_result("select top 20 * from [Database1].[dbo].[增值业务数据提交] where 工号='" user_id "' and 外呼日期=cast(cast(getdate() as date) as nvarchar) and 接通情况 is not null order by id desc")
;按行分割
StringSplit, line, result, `n
loop % line0
{
;赋值临时行
tmp_line = % line%A_index%
if tmp_line<> ;不为空
{
StringSplit, var, tmp_line, `,
LV_Add("",var1,var2,var3,var4,var5,var6,var7,var8,var9,var10,var11,var12,var13,var14,var15,var16,var17,var18)
}
}
;自动调整列宽
LV_ModifyCol()
Return
choose:
WinGetPos, x, y, , , xx呼叫中心增值业务
gui, main:Hide
WinHide, xx呼叫中心增值业务
;查询目标任务表中放行的目标客户表中的数据
result := get_result("SELECT [地区]+[外呼业务]+[语种]+cast([导入日期] as nvarchar) FROM [Database1].[dbo].[增值业务目标客户] where [地区]+[外呼业务]+[语种]+cast([导入日期] as nvarchar) in (SELECT [地区]+[外呼业务]+[语种]+cast([导入日期] as nvarchar) FROM [Database1].[dbo].[增值业务目标任务] where locked=0 and [语种]='" user_lang "') group by [地区]+[外呼业务]+[语种]+cast([导入日期] as nvarchar)")
gui, 2:Destroy
StringReplace, tasks, result, `n, |, All
gui, 2:add, DropDownList, x0 y0 w300 h600 vctask, %tasks%
gui, 2:add, Button, x300 y0 w40 h20 gsubchoose,确定
gui, 2:show, x%x% y%y% , 选择任务
Return
subchoose:
GuiControlGet, ctask
gui, 2:Destroy
gui, main:show
GuiControl, main:, task_name, %ctask%
;显示任务信息,15间隔重复
SetTimer, show_task_info, 15000
oldtime = %A_TickCount%
goto, get_task
Return
get_task:
;检查是否有该工号占有但是没有提交的数据 提交的数据会有sid
if (get_1_result("SELECT count(*) FROM [Database1].[dbo].[增值业务目标客户] where [地区]+[外呼业务]+[语种]+cast([导入日期] as nvarchar)='" ctask "' and 工号='" user_id "' and sid is null")<1)
{
;占有一个
effect_row := get_rowcount("update [Database1].[dbo].[增值业务目标客户] set 工号='" user_id "' where id=(SELECT TOP 1 id FROM [Database1].[dbo].[增值业务目标客户] where [地区]+[外呼业务]+[语种]+cast([导入日期] as nvarchar)='" ctask "' and 工号 is null)")
}
;获取已占有数据量
tmp_rows := get_1_result("SELECT count(*) FROM [Database1].[dbo].[增值业务目标客户] where [地区]+[外呼业务]+[语种]+cast([导入日期] as nvarchar)='" ctask "' and 工号='" user_id "' and sid is null")
if tmp_rows > 0
{
;获取已占有数据
tmp_row := get_1_result("SELECT TOP 1 * FROM [Database1].[dbo].[增值业务目标客户] where [地区]+[外呼业务]+[语种]+cast([导入日期] as nvarchar)='" ctask "' and 工号='" user_id "' and sid is null")
;分割数据
StringSplit, tmp_var, tmp_row, `,
area := tmp_var1
phone := tmp_var2
business := tmp_var3
id := tmp_var6
GuiControl, main:, phone, %phone%
}
Else
{
MsgBox, 4112, 提示, 当前任务已空!
}
Return
show_task_info:
GuiControl, main:, task_info, % "当前任务总量:" get_1_result("SELECT count(*) FROM [Database1].[dbo].[增值业务目标客户] where [地区]+[外呼业务]+[语种]+cast([导入日期] as nvarchar)='" ctask "'")
Sleep, 2800
GuiControl, main:, task_info, % "当前任务剩余量:" get_1_result("SELECT count(*) FROM [Database1].[dbo].[增值业务目标客户] where [地区]+[外呼业务]+[语种]+cast([导入日期] as nvarchar)='" ctask "' and [工号] is null")
Sleep, 2800
GuiControl, main:, task_info, % "您当日的外呼量:" get_1_result("select count(*) from [Database1].[dbo].[增值业务数据提交] where 工号='" user_id "' and 外呼日期=cast(getdate() as date) and 接通情况 is not null")
Sleep, 2800
GuiControl, main:, task_info, % "您当日的外呼成功量:" get_1_result("select count(*) from [Database1].[dbo].[增值业务数据提交] where 工号='" user_id "' and 外呼日期=cast(getdate() as date) and 接通情况='成功' and (质检结果 is null or 质检结果='合格')")
Sleep, 2800
GuiControl, main:, task_info, % "您当日的质检不合格量:" get_1_result("select count(*) from [Database1].[dbo].[增值业务数据提交] where 工号='" user_id "' and 外呼日期=cast(getdate() as date) and 接通情况='成功' and 质检结果='不合格'")
Return
;ping检查网络函数
ping(ip){
RunWait, %ComSpec% /c ping -n 1 %ip% >%A_Temp%\ahk_ping.tmp, , Hide
FileRead, content, %A_Temp%\ahk_ping.tmp
StringReplace, content, content, `r, , All
StringSplit, var, content, `n
If content Contains 请求超时,Request timed out
Return "请求超时"
If content Contains 找不到主机,could not find host
Return "找不到主机"
If content Contains 无法访问目标主机,Destination host unreachable
Return "无法访问目标主机"
Else
{
time := RegExReplace(var3, "(来自|Reply from) \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}[\s的回复|]*: (字节|bytes)=\d{1,3}\ (时间|time)[=<](\d{1,3})ms TTL=\d{1,3}","$4")
Return "正常 time:" time "ms"
}
}
;转码函数
urlencode(string,utf8:=1){
if (utf8=1 && A_IsUnicode<>1)
{
clip := ClipboardAll
Clipboard = %string%
Transform, string, Unicode
Clipboard := clip
}
StringLen, len, string
Loop % len
{
SetFormat, IntegerFast, hex
StringMid, out, string, %A_Index%, 1
hex := Asc(out)
hex2 := hex
StringReplace, hex, hex, 0x, , All
SetFormat, IntegerFast, d
hex2 := hex2
If (hex2==33 || (hex2>=39 && hex2 <=42) || hex2==45 || hex2 ==46 || (hex2>=48 && hex2<=57) || (hex2>=65 && hex2<=90) || hex2==95 || (hex2>=97 && hex2<=122) || hex2==126)
content .= out
Else
content .= "`%" hex
}
Return content
}
;执行SQL并返回带标题的csv逗号分隔格式的结果的函数
get_result_with_colname(sql){
global api ;全局变量
URLDownloadToFile, % api "?str=" urlencode(sql "))))") "&o=1", %A_Temp%\res_with_colname.tmp
FileRead, result, %A_Temp%\res_with_colname.tmp
Return result
}
;执行SQL并返回不带标题的csv逗号分隔格式的结果的函数
get_result(sql){
global api
URLDownloadToFile, % api "?str=" urlencode(sql "))))"), %A_Temp%\res.tmp
FileRead, result, %A_Temp%\res.tmp
Return result
}
;执行SQL并返回不带标题的csv逗号分隔格式的第一项结果的函数
get_1_result(sql){
global api
URLDownloadToFile, % api "?str=" urlencode(sql "))))"), %A_Temp%\1res.tmp
FileReadLine, result, %A_Temp%\1res.tmp, 1
Return result
}
;执行SQL并返回影响结果数量的函数
get_rowcount(sql){
global api
URLDownloadToFile, % api "?str=" urlencode(sql "))))") "&o=2", %A_Temp%\rowcount
FileReadLine, result, %A_Temp%\rowcount.tmp, 1
Return result
}
loginGuiclose:
mainGuiClose:
ExitApp
ahk+php+sqlserver呼叫中心外呼数据提交工具案例.zip
<?php
//连接
$c = new PDO( "sqlsrv:server=(local); Database = ", "sa", "123456", array(PDO::SQLSRV_ATTR_DIRECT_QUERY => true));
//返回不含字段名称的查询
function query($query){
global $c;
//定义全局变量
$stmt = $c->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->execute();
global $rowcount;
$rowcount=NULL;
//判断sql类型
$rowcount = $stmt->rowCount();
if(stripos($query, 'update') !== false){
return "UP".$rowcount;
}elseif(stripos($query, 'delete') !== false){
return "DE".$rowcount;
}elseif(stripos($query, 'insert') !== false){
return "IN".$rowcount;
}else{
//初始化变量
$content=NULL;
if( $stmt->rowCount() == 0){
return "";
}else{
while ( $row = $stmt->fetch( PDO::FETCH_NUM ) ){
for($i = 0; $i < $stmt->columnCount(); $i++)
{
$type=gettype($row[$i]);
//判断是否object类型
if ($type=="object"){
$var=$row[$i];
//格式化时间
$time=str_replace("T"," ",$var->format(DateTime::ISO8601));
$time=substr($time,0,19);
$time=$time.".000";
$content=$content.$time.",";
}else{
$ctmp=str_replace(",",",",$row[$i]);
$content=$content.$ctmp.",";
//追加
}
}
$content=$content."\n";
}
$content=str_replace(",\n","\n",$content);
return $content;
}
}
}
//返回含字段名称的查询
function qt($query){
global $c;
$stmt = $c->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->execute();
global $rowcount;
$rowcount=NULL;
$rowcount = $stmt->rowCount();
if(stripos($query, 'update') !== false){
return "UP".$rowcount;
}elseif(stripos($query, 'delete') !== false){
return "DE".$rowcount;
}elseif(stripos($query, 'insert') !== false){
return "IN".$rowcount;
}else{
$content=NULL;
if( $stmt->rowCount() == 0){
return "NO";
}else{
$a = $stmt->fetch( PDO::FETCH_ASSOC);
$Fields = array_keys($a);
global $titles;
$titles=NULL;
//循环获取字段名称
for($i = 0; $i < $stmt->columnCount(); $i++)
{
$name=iconv('GB2312','UTF-8',$Fields[$i]);
$titles=$titles."$name,";
}
$titles=$titles."\r\n";
$titles=str_replace(",\r\n","",$titles);
$content = $titles."\r\n";
$stmt->execute();
while ( $row = $stmt->fetch( PDO::FETCH_NUM ) ){
for($i = 0; $i < $stmt->columnCount(); $i++)
{
$type=gettype($row[$i]);
if ($type=="object"){
$var=$row[$i];
$time=str_replace("T"," ",$var->format(DateTime::ISO8601));
$time=substr($time,0,19);
$time=$time.".000";
$content=$content.$time.",";
}else{
$ctmp=str_replace(",",",",$row[$i]);
$content=$content.$ctmp.",";
}
}
$content=$content."\r\n";
}
$content=str_replace(",\r\n","\r\n",$content);
return $content;
}
}
}
//仅执行
function get($sql){
global $c;
global $result;
$result = $c->prepare( $sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$result->execute();
global $rowcount;
$rowcount=NULL;
$rowcount = $result->rowCount();
}
?>
49 queries in 1.808 seconds |