xRGamingx Posted February 8, 2018 Share Posted February 8, 2018 Hello friends, how can I know that the Login connection is correct with SQL? I want some message to appear in the debug script 3 that tells me that the connection is successful to the dbsql Or tell me failed connection.. local server ="test" local base ="test" local user ="test" local contra="test" function registrar(user,clave,correo) cnn = dbConnect( "mysql", "dbname="..base..";host="..server,user,contra,"share=2") res = dbQuery( cnn,"select count(codCuentas)as nombre from cuentas where usuario='"..user.."';") result = dbPoll( res, -1 ) if(result[1]["nombre"]==0)then serial = getPlayerSerial(source) res = dbQuery( cnn,"select count(codCuentas)as nombre from cuentas where serialPlayer='"..serial.."';") result = dbPoll( res, -1 ) if(result[1]["nombre"]<100)then a,b,c = tostring(math.random(100,800)),tostring(math.random(100,800)),tostring(math.random(100,800)) codigo = a..b..c fail= dbExec( cnn, "INSERT INTO cuentas(usuario,clave,correo,serialPlayer,codigo,cambio,can,activa) VALUES (?,?,?,?,?,?,?,?)",user,clave,correo,serial,codigo,0,0,0 ) if(addAccount(user,clave))then outputChatBox("The account was created successfully Usero="..user.." Pass="..clave,source) setElementData(source,"usuario",user) setElementData(source,"clave",clave) enviar(codigo,correo,"Codigo+De+activacion",source) triggerClientEvent(source,"fActivar",source) else outputChatBox("Something has gone wrong contact an admin",source) end else outputChatBox("You can only have 2 accounts",source) end else outputChatBox("The account is already in use",source) end end addEvent("registrar",true) addEventHandler("registrar",getRootElement(),registrar) Link to comment
NeXuS™ Posted February 8, 2018 Share Posted February 8, 2018 (edited) If the connection failed, you should get an error. cnn = dbConnect( "mysql", "dbname="..base..";host="..server,user,contra,"share=2") if cnn then outputDebugString("MySQL connected.") else outputDebugString("MySQL couldn't connect.") end function registrar(user,clave,correo) res = dbQuery( cnn,"select count(codCuentas)as nombre from cuentas where usuario='"..user.."';") result = dbPoll( res, -1 ) ... end And I'd consider using dbPoll with a time limit of -1, because it can cause freezes. Edited February 8, 2018 by NeXuS™ Link to comment
xRGamingx Posted February 9, 2018 Author Share Posted February 9, 2018 local server ="127.0.0.1" local base ="proyectotg" local user ="root" local contra="" --server =host --base =dbname --user =user --contra= pass function registrar(user,clave,correo) cnn = dbConnect( "mysql", "dbname="..base..";host="..server,user,contra,"share=2") res = dbQuery( cnn,"select count(codCuentas)as nombre from cuentas where usuario='"..user.."';") result = dbPoll( res, -1 ) if(result[1]["nombre"]==0)then serial = getPlayerSerial(source) res = dbQuery( cnn,"select count(codCuentas)as nombre from cuentas where serialPlayer='"..serial.."';") result = dbPoll( res, -1 ) if(result[1]["nombre"]<100)then a,b,c = tostring(math.random(100,800)),tostring(math.random(100,800)),tostring(math.random(100,800)) codigo = a..b..c fail= dbExec( cnn, "INSERT INTO cuentas(usuario,clave,correo,serialPlayer,codigo,cambio,can,activa) VALUES (?,?,?,?,?,?,?,?)",user,clave,correo,serial,codigo,0,0,0 ) if(addAccount(user,clave))then outputChatBox("The account was created successfully Usero="..user.." Pass="..clave,source) setElementData(source,"usuario",user) setElementData(source,"clave",clave) enviar(codigo,correo,"Codigo+De+activacion",source) triggerClientEvent(source,"fActivar",source) else outputChatBox("Something has gone wrong contact an admin",source) end else outputChatBox("You can only have 2 accounts",source) end else outputChatBox("The account is already in use",source) end end addEvent("registrar",true) addEventHandler("registrar",getRootElement(),registrar) [2018-02-08 20:58:21] WARNING: Login\server.lua:8: Bad usage @ 'dbConnect' [Accès refusé pour l'utilisateur: ''@'@localhost'. Base 'proyectotg'] [2018-02-08 20:58:27] WARNING: Login\server.lua:9: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got boolean] [2018-02-08 20:58:27] WARNING: Login\server.lua:10: Bad argument @ 'dbPoll' [Expected db-query at argument 1, got boolean] [2018-02-08 20:58:27] ERROR: Login\server.lua:11: attempt to index global 'result' (a boolean value) Link to comment
NeXuS™ Posted February 9, 2018 Share Posted February 9, 2018 Try setting a password for the root user in your phpMyAdmin. And please change to English language or translate the errors next time. And I already wrote that you should move the dbConnect out of the function, as you don't want to connect to it every single time it is called. 1 Link to comment
xRGamingx Posted February 9, 2018 Author Share Posted February 9, 2018 1 hour ago, NeXuS™ said: Try setting a password for the root user in your phpMyAdmin. And please change to English language or translate the errors next time. And I already wrote that you should move the dbConnect out of the function, as you don't want to connect to it every single time it is called. 1- I did everything right as you asked and it worked 2- The login sends the account to the phpmyadmin page 3- But I get a single error when creating the account Is --> [2018-02-08 22:24:36] WARNING: Login\server.lua:21: Access denied @ 'addAccount' -------------------------------------------- Line 21 --> if(addAccount(user,clave))then But I do not understand why I get that error if the login sends the data to phpmyadmin rather Link to comment
NeXuS™ Posted February 9, 2018 Share Posted February 9, 2018 (edited) The error is created by MTA. You have to give ACL access to the resource, the same as you had to do to your user. Just replacing "user.username" with "resource.resourcename". Edited February 9, 2018 by NeXuS™ Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now