Perform update and insert in mysql via asp classic

1

Good morning people

I would like to help a little bit boring, maybe even something banal

I have a page in asp connect.asp as follows

 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%

<%
dim conn

sub AbreConn()
'Criamos o objeto de conexão
Set conn = Server.CreateObject("ADODB.Connection") 

'Abrimos uma conexão com o banco de dados
conn.Open("DRIVER={MySQL ODBC 5.1 Driver};SERVER=server;PORT=3306;DATABASE=database;USER=usuario;PASSWORD=senha;OPTION=3;")
conexao_executa=true 

end sub

sub fechaConn()
'Fechamos a conexão com o banco de dados
conn.Close() 
'Destruímos o objeto
Set conn = Nothing
end sub

'sub que executara comandos no bd
sub executaconexao(comando)
    if conexao_executa=false then
        call AbreConn
    end if
    response.Write(comando)
    set objComando = Server.CreateObject("ADODB.Command")
    objComando.ActiveConnection = conn
    objComando.CommandText = comando
    objComando.Execute() 
    Set objComando = Nothing
    call fechaConn

end sub
%>

I can not run the select's , but it does not usually have any errors. However, at the time of doing an update or insert it does not execute anything,

If anyone has any suggestions on what can be done thank you.

Below is how I call the update on page envia.asp

sql ="update produtos set descricao_produto = '" & server.HTMLEncode(request.form("elm1")) & "' where codigo_chave = 32"

executaconexao(sql)
    
asked by anonymous 04.01.2016 / 14:45

1 answer

1

Brother refactored your code and hopefully helped a little bit change ok

I used the conn.execute () on the sub executionet () to decrease the code.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<%
dim conn

sub AbreConn()
    'Criamos o objeto de conexão
    Set conn = Server.CreateObject("ADODB.Connection") 
    ''Abrimos uma conexão com o banco de dados
    'conn.Open("DRIVER={MySQL ODBC 5.1 Driver};SERVER=server;PORT=3306;DATABASE=database;USER=usuario;PASSWORD=senha;OPTION=3;")
    conexao_executa=true

    Servidor = "localhost"
    dsnName = "gsc" 'The name of the DSN
    dsnUser = "wilson" 'The username for the DSN
    dsnPass = "wilson26" 'The password for the DSN
    database = "gsc" 'The database to use
    stringer = "Provider=MSDASQL;Driver={MySQL ODBC 5.3 ANSI Driver};Server="&Servidor&";Database="&database&";User="&dsnUser&";Password="&dsnPass&";Option=3;"
    conn.Open stringer
end sub

sub fechaConn()
    'Fechamos a conexão com o banco de dados
    conn.Close() 
    'Destruímos o objeto
    Set conn = Nothing
end sub

'sub que executara comandos no bd
sub executaconexao(comando)
    call AbreConn()
    if conexao_executa=false then       
        conn.execute(comando)
        response.write comando
        call fechaConn()
    end if
end sub

sql = "insert into gsc.cadastro_cargo(cargo) values('boina verde');"
executaconexao(sql)

%>
    
20.02.2016 / 19:01