Hvordan får man denne kode til at snakke med MySQL DB
Jeg har nu brugt en del timer på at prøve at få denne kode omskreven til at virke med en MySQL DB i stedet for en Access DB man jeg kan ikke få det til at virke hvordan omskriver man kode?Håber der er nogle som kan hjælp mig.
inc.asp
-----------------
<%
Sub LavDatabase(oConn)
Dim AccessDB, myDSN
AccessDB = "/menu/menu.mdb"
myDSN = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath(accessdb)
Set oConn = Server.CreateObject("ADODB.Connection")
On Error Resume Next
oConn.Open myDSN
If Err.Number<>0 Then
Response.Write "<BR><HR>Database connection error.<BR>"
Response.Write "Fejl beskrivelse: " & err.description & "<BR>"
Response.Write "Connectionstring: " & mydsn & "<BR>"
Response.End
End If
On Error GOTO 0
End Sub
Sub LukDatabase(oConn)
oConn.Close
Set oConn = Nothing
End Sub
Sub OpenRS(oConn, SQL, RS)
On Error Resume Next
Err.Clear
Set RS = Nothing
Set RS = CreateObject("ADODB.Recordset")
Call RS.Open(SQL, oConn,3)
If Err.Number<>0 Then
Response.Write "<BR><HR>"
Response.Write "Databasefejl:<BR>"
Response.Write "SQL: " & sql & "<BR>"
Response.Write "Fejlmeddelelse: " & err.description & "<BR>"
Response.End
End If
On Error GOTO 0
End Sub
%>
menu.asp
-----------------
<!-- #INCLUDE FILE="inc.asp" -->
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT>
function MenuClick(MenuID) {
var txt = document.all("txt_" + MenuID);
if (txt.style.display == 'none') {
txt.style.display = '';
}
else {
txt.style.display = 'none';
}
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<%
Function BygUnderMenu(MenuID)
UnderSQL = "SELECT ID, Navn, Link FROM Menu WHERE MenuID = " & MenuID & " ORDER BY [Order]"
Call OpenRS(Conntemp,UnderSQL,UnderRS)
Response.Write "<DIV ID=""txt_" & MenuID & """ STYLE=""display: none; margin-left: 10px;"">"
While Not UnderRS.EOF
If CountSubs(UnderRS("ID")) > 0 Then
Response.Write "<A HREF=""#"" OnClick=""MenuClick(" & UnderRS("ID") & ")""><B>" & UnderRS("Navn") & "</B></A><BR>"
BygUnderMenu UnderRS("ID")
Else
Response.Write "<A HREF=""" & UnderRS("Link") & """ TARGET="""">" & UnderRS("Navn") & "<BR>"
End If
UnderRS.MoveNext
Wend
Response.Write "</DIV>"
End Function
Function CountSubs(MenuID)
CountSQL = "SELECT ID FROM Menu WHERE MenuID = " & MenuID & ""
Call OpenRS(Conntemp,CountSQL,CountRS)
CountSubs = CountRS.RecordCount
End Function
LavDatabase Conntemp
SQL = "SELECT ID, Navn, Link FROM Menu WHERE MenuID = 0 ORDER BY [Order]"
Call OpenRS(Conntemp,SQL,RS)
If RS.BOF AND RS.EOF Then
Response.Write "FEJL"
Else
RS.MoveFirst
While Not RS.EOF
If CountSubs(RS("ID")) > 0 Then
Response.Write "<A HREF=""#"" OnClick=""MenuClick(" & RS("ID") & ")""><B>" & RS("Navn") & "</B></A><BR>"
BygUnderMenu RS("ID")
Else
Response.Write "<A HREF=""" & RS("Link") & """>" & RS("Navn") & "<BR>"
End If
RS.MoveNext
Wend
End If
LukDatabase Conntemp
%>
</BODY>
</HTML>