最近参与了一个ASP项目,而且这也是自己第一次进行web方面的编程;作为3P之一的ASP应该是很老的技术了,但这并妨碍自己的积累和学习,尤其是web编程方面。在这里我想跟大家分享下在ASP服务端如何 通过 ADO 访问 ACCESS和SQL SERVER: ADO是一个 访问 数据库中
最近参与了一个ASP项目,而且这也是自己第一次进行web方面的编程;作为3P之一的ASP应该是很老的技术了,但这并妨碍自己的积累和学习,尤其是web编程方面。在这里我想跟大家分享下在ASP服务端如何通过ADO访问ACCESS和SQL SERVER:
ADO是一个访问数据库中数据的编程接口,是微软的一个Active-x组件,会随IIS被自动安装;在做ASP编程的时候,安装IIS(即Internet informations service)是必不可少的;
首先确保OS上已正确安装了ACCESS和SQL SERVER,由于家里电脑上没有装SQL SERVER,下面以在xp平台上访问ACCESS2003数据库为例来测试下自己写的几个数据库访问函数
1.通过.udl文件获取数据库连接字符串
1)新建一个txt文件,并修改后缀名为.udl;直接双击打开该udl文件后我们就可以根据需要获取特定数据库的连接字符串了;打开udl后的界面如图-1所示:
图-1
2)在这里我们选择Microsoft.Jet.OLEDB.4.0数据库提供程序来访问access,点击下一步后界面如图-2所示:
图-2
3)输入或选择数据库所在路径后,其它选项保持默认,点击测试连接后,没有问题的情况下会弹出提示【测试连接成功】的消息框;
这时,我们点击确定后用UE或者其它文本编辑工具打开该udl文件后,即可获取连接该access数据库的连接字符串;
如图-3所示:这里的连接字符串即为:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\IIS\webapps\My_Test\GXY_DB1.mdb;Persist Security Info=False
图-3
2.通过连接字符串创建相关数据库操作函数
1.)新建ProDatBase.asp文件,并插入空的ASP代码段;在该代码段中声明三个全局变量;分别用来存储ADO记录集对象、ADO连接对象、以及连接字符串;
将上面获取的连接字符串赋值给g_ConStr
<p><span>Dim g_Rs,g_Con,g_ConStr</span></p><p><span>g_ConStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\IIS\webapps\My_Test\GXY_DB1.mdb;Persist Security Info=False"</span></p>2.)创建数据连接和断开连接函数
'连接数据库 function ConnectDataBase() set g_Con=server.CreateObject("ADODB.connection") on error resume next g_Con.mode=3 '将连接模式设为可读取写 g_Con.open g_ConStr if err0 then ConnectDataBase=false response.Write(err.Description) else ConnectDataBase=true end if end function '断开数据库连接 function DisconnectDataBase() on error resume next g_Con.close set g_Con=nothing if err0 then DisconnectDataBase=false response.Write(err.Description) else DisconnectDataBase=true end if end function3.)创建插入记录函数
'插入记录 function InsertRecord(table,sqlFields,sqlValues) if ConnectDataBase() then sql="insert into ["+table+"] ("+sqlFields+") values ("+sqlValues+") " on error resume next g_Con.Execute sql if err 0 then response.Write(err.Description) end if DisconnectDataBase() end if end function
4.)创建更新记录函数
'更新记录 function UpdateRecord(table,sqlFields,sqlValues,strCondition) if ConnectDataBase() then sql="update ["+table+"] set " sql_fd=split(sqlFields,",") sql_fv=split(sqlValues,",") for i=0 to ubound(sql_fd) if iubound(sql_fd) then sql=sql & ""&sql_fd(i)&"="&sql_fv(i)&"," else sql=sql & ""&sql_fd(i)&"="&sql_fv(i)&"" end if next sql=sql&" where "&strCondition&"" on error resume next g_Con.Execute sql if err 0 then response.Write(err.Description) end if DisconnectDataBase() end if end function
5.)创建删除记录函数
'根据条件删除记录 function DeleteRecord(table,strCondition) if ConnectDataBase() then sql="delete from "+table+" where "&strCondition&" " on error resume next g_Con.Execute sql if err 0 then response.Write(err.description) end if DisconnectDataBase() end if end function
6.)创建记录获取函数
'根据条件获取记录 function GetRecords(table,strCondition) if ConnectDataBase() then sql="select * from ["+table+"]" if strCondition "" then sql=sql&" where "&strCondition&"" end if on error resume next set g_Rs=Server.CreateObject("ADODB.recordset") g_Rs.Open sql,g_Con if err 0 then response.Write(err.description) end if end if end function
7.)创建资源释放函数
function ReleaseResource() on error resume next g_Rs.close set g_Rs=nothing DisconnectDataBase() if err0 then response.Write(err.description) end if end function
3、对创建的数据库函数进行测试,这里以GXY_DB1数据库下的表Test_table为例,该表的各字段及全部记录如图-4和图-5所示:
图-4(id自动增长) 图-5(没有记录)
准备:新建ProDataBase_Test.asp文件,添加包含ProDataBase.asp文件的语句,插入空的asp代码块
1.)插入记录函数测试:插入10条记录,name和age依次从name0和15岁到name9和24岁
测试代码:
测试结果如图-6所示:
图-6
2.)获取记录函数测试:获取age在18到23之间的记录并显示在网页上
测试代码:
<div align="center"> Test_Table <table border="2" bgcolor="#99FFFF"> ") for each x in g_Rs.fields response.Write("<th>") response.write(x.name) response.Write("</th>") next response.Write("") do until g_Rs.eof response.Write("<tr>") for each x in g_Rs.fields response.Write("<td width="90">") response.write(x.value) response.Write("</td>") next response.Write("</tr>") g_Rs.movenext loop ReleaseResource() %> </table> </div>
测试结果如图-7所示:
图-7
3.)更新记录函数测试:将name=name7的记录的name改为newname,age改为99岁,并将获取所有记录显示在网页上
测试代码:
<div align="center"> Test_Table <table border="2" bgcolor="#99FFFF"> ") for each x in g_Rs.fields response.Write("<th>") response.write(x.name) response.Write("</th>") next response.Write("") do until g_Rs.eof response.Write("<tr>") for each x in g_Rs.fields response.Write("<td width="90">") response.write(x.value) response.Write("</td>") next response.Write("</tr>") g_Rs.movenext loop ReleaseResource() %> </table> </div>
测试结果如图-8所示:
图-8
4.)删除记录函数测试:删除age大于18岁的记录,并将获取所有记录显示在网页上
测试代码:
<div align="center"> Test_Table <table border="2" bgcolor="#99FFFF"> 18" GetRecords "Test_Table","" response.Write("<tr>") for each x in g_Rs.fields response.Write("<th>") response.write(x.name) response.Write("</th>") next response.Write("</tr>") do until g_Rs.eof response.Write("<tr>") for each x in g_Rs.fields response.Write("<td width="90">") response.write(x.value) response.Write("</td>") next response.Write("</tr>") g_Rs.movenext loop ReleaseResource() %> </table> </div>
测试结果如图-9所示:
图-9
4.总结:
上述所有函数在win7和xp平台以及access2003和sql server2008 express版(vs2010自带的)上均测试过,可以正常运行;下面提供一个连接sql server2008的连接字符串供参考:(也是通过udl文件创建的,数据提供程序选择sql server native client 10.0)
g_ConStr="Provider=SQLNCLI10.1;Persist Security Info=False;User ID=gxy;Password=54321;Initial Catalog=GXY_DB1;Data Source=(local);第一次发博客,文笔又不行,vbscript刚接触,函数写的不够高效及简洁。。。等等。。。。。如有不当及纰漏之处,请各路大牛多多指教

mysqlviewshavelimitations:1)supportallsqloperations、制限、dataManipulationswithjoinsorubqueries.2)それらは、特にパフォーマンス、特にパルフェクソルラージャターセット

reperusermanmanagementInmysqliscialforenhancingsecurationsinginuring databaseaperation.1)usecreateusertoaddusers、指定connectionsourcewith@'localhost'or@'% '。

mysqldoes notimposeahardlimitontriggers、しかしpracticalfactorsdeTerminetheireffectiveuse:1)serverconufigurationStriggermanagement; 2)complentiggersincreaseSystemload;

はい、それはssafetostoreblobdatainmysql、butonsiderheSeCactors:1)Storagespace:blobscanconsumesificantspace.2)パフォーマンス:パフォーマンス:大規模なドゥエットブロブスメイズ階下3)backupandrecized recized recized recize

PHP Webインターフェイスを介してMySQLユーザーを追加すると、MySQLI拡張機能を使用できます。手順は次のとおりです。1。MySQLデータベースに接続し、MySQLI拡張機能を使用します。 2。ユーザーを作成し、CreateUserステートメントを使用し、パスワード()関数を使用してパスワードを暗号化します。 3. SQLインジェクションを防ぎ、MySQLI_REAL_ESCAPE_STRING()関数を使用してユーザー入力を処理します。 4.新しいユーザーに権限を割り当て、助成金ステートメントを使用します。

mysql'sblobissuitable forstoringbinarydatawithinarationaldatabase、whileenosqloptionslikemongodb、redis、andcassandraofferferulesions forunstructureddata.blobissimplerbutcanslowdowdowd withwithdata

toaddauserinmysql、使用:createuser'username '@' host'identifidedby'password '; here'showtodoitsely:1)chosehostcarefilytoconを選択しますTrolaccess.2)setResourcelimitslikemax_queries_per_hour.3)usestrong、uniquasswords.4)endforcessl/tlsconnectionswith

toavoidcommonMonmistakeswithStringDatatypesinmysql、undultingStringTypenuste、choosetherightType、andManageEncodingandCollationsEttingtingive.1)Usecharforfixed-LengthStrings、Varcharforaible Length、AndText/Blobforlardata.2)setCurrectCherts


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

ドリームウィーバー CS6
ビジュアル Web 開発ツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

SublimeText3 中国語版
中国語版、とても使いやすい
