MySQL / Classic ASP - Parameterized Queries

前端 未结 1 802
不思量自难忘°
不思量自难忘° 2021-01-15 02:08

In an absolute emergency, I am trying to go through my website and add parameterized queries. I\'m a newbie and have only just learnt about them.

My problem is, I on

1条回答
  •  野的像风
    2021-01-15 02:18

    The code in your second snippet is correct, but should be applied to a new ADODB.Command object, not to the Connection object:

    username = Trim(Request("username"))
    
    '-----Added this-----
    Dim cmdContent
    Set cmdContent = Server.CreateObject("ADODB.Command")
    
    ' Use this line to associate the Command with your previously opened connection
    Set cmdContent.ActiveConnection = connContent
    '--------------------
    
    cmdContent.Prepared = True
    
    Const ad_nVarChar = 202
    Const ad_ParamInput = 1
    
    SQL = " SELECT * FROM users WHERE (username=?) ; "
    
    Set newParameter = cmdContent.CreateParameter("@username", ad_nVarChar, ad_ParamInput, 20, username)
    cmdContent.Parameters.Append newParameter
    
    cmdContent.CommandText = SQL
    Set rs = cmdContent.Execute
    
    If NOT rs.EOF Then
            ' Do something...
    End If
    
    rs.Close
    

    By the way, there was a typo with the spelling of adParamInput instead of ad_ParamInput (corrected in my example).

    0 讨论(0)
提交回复
热议问题