ASP運算元據庫的函式庫

2021-09-06 06:44:13 字數 4188 閱讀 9311

<%'

************************************===

'* 名稱:usedb.asp

'* 功能:資料庫操作函式庫''

* 信箱:[email protected]

'* 主頁:

'* blog:

'************************************===

'* 函式:opendb(dbtype,dbuser,dbpass,dbname,dbserver,dbpath)

'* 功能:開啟資料庫連線

'* 引數:dbtype->資料庫型別 mdb access資料庫 || sqlserver sqlserver資料庫

'* 引數:dbuser->訪問資料庫使用者名稱

'* 引數:dbpass->訪問資料庫密碼

'* 引數:dbname->資料庫名稱

'* 引數:dbserver->資料庫host

'* 引數:dbpath->資料庫路徑

function opendb(dbtype,dbuser,dbpass,dbname,dbserver,dbpath)

dim conn

set conn = server.createobject("

adodb.connection")

select

case

dbtype

case

"mdb":

connstr = "

driver=;dbq=

)case

"sqlserver":

connstr = "

provider=sqloledb.1;password=

"&dbpass&"

;persist security info=true;user id=

"&dbuser&"

;initial catalog=

"&dbname&"

;data source=

"&dbserver&""

end select

conn.open connstr

end function

'

* 函式:add(tabname,fieldlist,dblist)

'* 功能:在資料庫中插入一條記錄

'* 引數:tabname->資料表名

'* 引數:dblist->資料表欄位名陣列

'* 引數:fieldlist->表單變數名陣列

'* 返回:0 false || 1 true

function add(tabname,dblist,fieldlist)

sql = "

insert into

"&tabname&"("

value = ""

field = ""

for each v

indblist

field = field & v & ","

next

field = left(field,len(field)-1

) value = field & "

) values(

"for each v

infieldlist

if request.form(v)

<> ""

then

value = value & "

'" & request.form(v) & "',"

else

value = value & "

'" & v & "',"

end if

next

value = left(value,len(value)-1

) sql = sql & value & ")"

conn.execute(sql)

closedb()

if err then

add = 0

else

add = 1

end if

end function

'* 函式:update(tabname,dblist,fieldlist,id)

'* 功能:更新資料庫中指定的一條記錄

'* 引數:tabname->資料表名

'* 引數:dblist->資料庫欄位名稱陣列

'* 引數:fieldlist->表單變數名陣列

'* 引數:id->資料id號

'* 返回:0 false || 1 true

function update(tabname,dblist,fieldlist,id)

sql = "

update

" & tabname & "

set

"value = ""

for i=0

to ubound(dblist)

value = value & dblist(i) & "='"

if request.form(fieldlist(i))

<> ""

then

value = value & request.form(fieldlist(i)) & "',"

else

value = value & fieldlist(i) & "',"

end if

next

value = left(value,len(value)-1

) sql = sql & value & "

where id=

" &id

conn.execute(sql)

closedb()

if err then

update = 0

else

update = 1

end if

end function

'* 函式:del(tabname,id)

'* 功能:從資料庫中刪除一條指定記錄

'* 引數:tabname->資料表名稱

'* 引數:id->資料id號

'* 返回:0 false || 1 true

function del(tabname,id)

sql = "

delete from

" & tabname & "

where id in(

" & id & ")"

conn.execute(sql)

closedb()

if err then

del = 0

else

del = 1

end if

end function

'* 函式:getrow(tabname,fieldlist,casestr)

'* 功能:從資料庫中取得一行

'* 引數:tabname->資料表名

'* 引數:fieldlist->資料字段陣列

'* 引數:casestr->sql條件語句

function getrow(tabname,fieldlist,casestr)

if not isarray(fieldlist) then

fieldlist = "*"

else

field = ""

for each val

infieldlist

field = field & val & ","

next

fieldlist = left(field,len(field)-1

) end if

sql = "

select

" & fieldlist & "

from

" & tabname &casestr

set rs =conn.execute(sql)

if rs.eof and rs.bof then

getrow = 0

else

getrow = 1

end if

end function

'* 函式:closedb()

'* 功能:關閉資料庫連線並釋放物件

function closedb()

conn.close

set conn =nothing

end function

%>

ASP運算元據庫

adodb.connection 連線資料庫 先註冊乙個conn物件 set conn server.createobject adodb.connection 用server物件的createobject方法 然後再用connection的open方法連線資料庫 conn.execute inse...

ASP運算元據庫

adodb.connection 連線資料庫 先註冊乙個conn物件 set conn server.createobject adodb.connection 用server物件的createobject方法 然後再用connection的open方法連線資料庫 conn.execute inse...

運算元據庫

python importmysqldb defmydbtest conn mysqldb.connect host localhost user root passwd sa db b4img charset utf8 cursor conn.cursor sql select from imag...