| [點(diǎn)晴永久免費(fèi)OA]asp連接mysql數(shù)據(jù)庫詳細(xì)實(shí)現(xiàn)代碼
 想要asp能連接mysql數(shù)據(jù)庫,需要安裝MySQL ODBC 3.51 驅(qū)動(dòng)。 我們先看下面這段代碼,代碼如下: set conn = server.createobject("adodb.connection")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver};SERVER=127.0.0.1;DATABASE=Shops;USER=root;PASSWORD=xxx;"上面這代碼是核心部分了: SERVER 連接服務(wù)器如127.0.0.1 DATABASE 要選擇的數(shù)據(jù)庫 shops USER 服務(wù)器登錄用戶名 PASSWORD 服務(wù)器登錄密碼 好了下面來看實(shí)例,代碼如下: <%
'測試讀取MySql數(shù)據(jù)庫的內(nèi)容
strconnection="driver={mysql odbc 3.51 driver};database=weste_net;server=localhost;uid=root;password=" '無需配置dsn
set adodataconn = server.createobject("adodb.connection")
adodataconn.open strconnection
strquery = "select * from News"
set rs = adodataconn.execute(strquery)
if not rs.bof then
%>
<table>
<tr>
<td<b>序列號(hào)</b></td>
<td><b>標(biāo)題</b></td>
</tr>
<%
 do while not rs.eof
%>
<tr>
<td><%=rs("News_id")%></td>
<td><%=rs("News_Title")%></td>
</tr>
<%
 rs.movenext
 loop
%>
</table>
<%
else
 response.write("無數(shù)據(jù)。")
end if
rs.close
adodataconn.close
set adodataconn = nothing
set rsemaildata = nothing
%>注:上面我沒設(shè)置數(shù)據(jù)庫編碼,如果有中文亂碼可以嘗試設(shè)置客戶端字符編碼,代碼如下: conn.execute("set names '" & myChareSet & "'")如果要使用3306之外端口的話,我們就需要安裝Mysql的ODBC數(shù)據(jù)庫驅(qū)動(dòng),安裝之后代碼如下: Conn.Open "DRIVER={MySQL ODBC 3.51 Driver};SERVER=127.0.0.1;PORT=3333;DATABASE=Shops;USER=root;PASSWORD=xxx;"是沒有問題的。 該文章在 2022/6/21 17:25:25 編輯過 | 關(guān)鍵字查詢 相關(guān)文章 正在查詢... |