| FAQ |
| Kalender |
|
|
#1 | ||
|
|||
|
Medlem
|
Jag har gjort ett antal sidor i asp och med en set connection anslutning till min MySql databas. Det jobbiga kommer när jag vill göra en ändring på databasens namn och då måste jag ändra på så himla många sidor. Jag försökte med en SSI där jag skrev
"<% set connect = Server.CreateObject("Adodb.Connection") connect.Open "Driver={MySQL ODBC 3.51 Driver};Server=;Database=;UID=;PWD=" %>" Om jag lägger in detta koden ovan och döper den till setting så fungerar det inte. Så här <!--#include file="setting.asp" --> SQL = "SELECT * From bgcolor" set RS= connect.execute(SQL) Vad ska jag göra? |
||
|
|
Svara med citat
|
|
|
#2 | |||
|
||||
|
Nykomling
|
Vad får du för felmeddelande då?
Jag använder mig alltid av en funktion istället Functions.asp Kod:
Function ExecuteSQL(strSQL)
if(TypeName(dbConnection)<>"Connection") Then
OpenConnection()
End if
QueryCounter = QueryCounter +1
If InStr(1, strSQL, "UPDATE", 1) Or InStr(1, strSQL, "EXEC", 1) Or InStr(1, strSQL, "DELETE", 1) Or InStr(1, strSQL, "INSERT", 1) Then
dbConnection.Execute (strSQL), , 128
Else
Set ExecuteSQL = dbConnection.Execute(strSQL)
End If
End Function
Public Function GetDbRows(query)
if(TypeName(dbConnection)<>"Connection") Then
OpenConnection()
End if
QueryCount = QueryCount + 1
Set rs = dbConnection.Execute(query)
If rs.Eof Then
GetDbRows = Null
Else
GetDbRows = rs.GetRows()
End If
rs.Close : Set rs = Nothing
End Function
Function OpenConnection()
if(TypeName(dbConnection)<>"Connection") Then
Set dbConnection = Server.CreateObject("ADODB.Connection")
dbConnection.ConnectionTimeout = DB_CONNECTIONTIMEOUT
dbConnection.CommandTimeout = DB_COMMANDTIMEOUT
dbConnection.Open "Driver={MySQL ODBC 3.51 Driver}; Server=" & DB_SERVER & "; Port=" & DB_PORT & "; Database=" & DB_NAME & "; User=" & DB_USERNAME & "; Password=" & DB_PASSWORD & "; Option=3;"
End If
End Function
Function CloseConnection()
If(TypeName(dbConnection)="Connection") Then
dbConnection.Close : Set dbConnection = Nothing
End if
End Function
Kod:
<!-- #include virtual="/_inc/Functions.asp" -->
<%
Set rs = ExecuteSQL("SELECT * FROM bgcolor")
%>
Kod:
<!-- #include virtual="/_inc/Functions.asp" -->
<%
ExecuteSQL("DETELE FROM bgcolor")
%>
Kod:
<!-- #include virtual="/_inc/Functions.asp" -->
<%
arrPoster = getDbRows("SELECT farg, nummer FROM bgcolor")
If IsArray(arrPoster) Then
For iPost = 0 To UBound(arrPoster,2)
' LOOPAR UT POSTER
Farg = arrPoster(0,iPost)
Nummer = arrPoster(1,iPost)
Response.Write("FÄRGEN ÄR " & Farg & " OCH HAR FÄRGNUMMER " & Nummer & ".")
Next
Else
Response.Write("HITTADE INGA POSTER")
End If
%>
|
|||
|
|
Svara med citat
|
|
|
#3 | ||
|
|||
|
Medlem
|
Tack för alla hjälp. Jag tror att jag kan lösa problemet med din sida.
|
||
|
|
Svara med citat
|
|
|
#4 | ||
|
|||
|
Supermoderator
|
Annars är application en trevlig lösning.
__________________
Jonny Zetterström se.linkedin.com/in/jonnyz | bjz.se | sajthotellet.com | kalsongkungen.se | zretail.se | zetterstromnetworks.se | webbhotellsguide.se | ekonominyheter24.se | nyamobiltelefoner.se | gapskratt.se | antivirusguiden.se | jonny.nu |
||
|
|
Svara med citat
|
| Svara |
|
|