Oxsotus Posted June 21, 2013 Posted June 21, 2013 Hello! Sorry for my bad english... I have problem with my script. When I write the command (in the server) /bjel username password it doesn't select the character for the username I want to poll the user data from the mySQL server by username. Here is my script. First part, it works function csatlakozas() local adatbazis = dbConnect ( "mysql", "localhost" , "root", "" ) if(adatbazis)then outputChatBox("Sikeres csatlakozás!",source,0,255,0) end if not(adatbazis)then outputChatBox("Sikertelen csatlakozás! Lépj be újra!",source,255,0,0) end end addEventHandler("onPlayerJoin",getRootElement(),csatlakozas) And the second part, what doesn't works function login(jatekos, parancs, felhasznalonev, jelszo) local qh = dbConnect ( "mysql", "localhost" , "root", "" ) -- no password if(qh) then outputChatBox("Adatbázishoz történő csatlakozás sikeres!",jatekos,0,255,0) end --write the connection is succesfull character = dbQuery( qh, "SELECT `Character` FROM `players` WHERE `Username` = '?'", felhasznalonev ) local result, row = dbPoll( qh, -1 ) -- first error point this (I tryed it without the word "row", but doesnt works:( ) if(character) then outputChatBox("Karakter azonosítása sikeres!",jatekos,0,255,0) end -- second error point this outputChatBox(character,jatekos) end addCommandHandler("bjel",login) Here is the errors [2013-06-21 19:30:45] WARNING: rpg\account_system_server.lua:35: Bad argument @ 'dbPoll' [Expected db-query at argument 1, got db-connection] [2013-06-21 19:30:45] WARNING: rpg\account_system_server.lua:39: Bad argument @ 'outputChatBox' [Expected string at argument 1] I hope they can help me.
iPrestege Posted June 21, 2013 Posted June 21, 2013 table dbPoll ( handle queryHandle, int timeout ) Required Arguments queryHandle: A query handle previously returned from dbQuery I hope you know what's the problem now .
Oxsotus Posted June 21, 2013 Author Posted June 21, 2013 I function login(jatekos, parancs, felhasznalonev, jelszo) local qh = dbConnect ( "mysql", "localhost" , "root", "" ) if(qh) then outputChatBox("Adatbázishoz történő csatlakozás sikeres!",jatekos,0,255,0) end local qh = dbQuery( qh, "SELECT `Character` FROM `players` WHERE `Username` = '?'", felhasznalonev ) local result, row = dbPoll( qh, -1 ) end addCommandHandler("bjel",login) WARNING: rpg\account_system_server.lua:35: dbPoll failed; No database selected Could you link an example? (not from wiki) I want to select only one value and write it to the chatbox.
Oxsotus Posted June 21, 2013 Author Posted June 21, 2013 function login(jatekos, parancs, felhasznalonev, jelszo) local qh = dbConnect ( "mysql", "localhost" , "root", "" ) if(qh) then outputChatBox("Adatbázishoz történő csatlakozás sikeres!",jatekos,0,255,0) end local character = dbQuery( qh, "SELECT `Character` FROM `players` WHERE `Username` = '?'", felhasznalonev ) local result, row, errmsg = dbPoll( qh, -1 ) end addCommandHandler("bjel",login) WARNING: rpg\account_system_server.lua:35: Bad argument @ 'dbPoll' [Expected db-query at argument 1, got db-connection] Sorry, I don't know what's the problem
Vision Posted June 21, 2013 Posted June 21, 2013 Try to change this local result, row, errmsg = dbPoll( qh, -1 ) to this local result, row, errmsg = dbPoll ( character, -1 )
Oxsotus Posted June 21, 2013 Author Posted June 21, 2013 I changed, but now: WARNING: rpg\account_system_server.lua:35: dbPoll failed; No database selected
Oxsotus Posted June 21, 2013 Author Posted June 21, 2013 function login(jatekos, parancs, felhasznalonev, jelszo) local qh = dbConnect ( "mysql", "localhost" , "root", "" ) if(qh) then outputChatBox("Adatbázishoz történő csatlakozás sikeres!",jatekos,0,255,0) end local character = dbQuery( qh, "SELECT `Character` FROM `players` WHERE `Username` = '?'", felhasznalonev ) local result, row, errmsg = dbPoll ( character, -1 ) end addCommandHandler("bjel",login)
Castillo Posted June 21, 2013 Posted June 21, 2013 Post the arguments you used for dbConnect, all of them, just remove password and user.
Oxsotus Posted June 21, 2013 Author Posted June 21, 2013 I don't understand, what I need to post. You mean, to remove the username and password, like this: function login(player, command) local qh = dbConnect ( "mysql", "localhost" , "root", "" ) if(qh) then outputChatBox("Connecting to database succesful!",player,0,255,0) end local character = dbQuery( qh, "SELECT `Username` FROM `players`") local result, row, errmsg = dbPoll( qh, -1 ) end addCommandHandler("test",login) (I translate the variables name's to english)
iPrestege Posted June 21, 2013 Posted June 21, 2013 I don't understand, what I need to post.You mean, to remove the username and password, like this: function login(player, command) local qh = dbConnect ( "mysql", "localhost" , "root", "" ) if(qh) then outputChatBox("Connecting to database succesful!",player,0,255,0) end local character = dbQuery( qh, "SELECT `Username` FROM `players`") local result, row, errmsg = dbPoll( qh, -1 ) end addCommandHandler("test",login) (I translate the variables name's to english) local result, row, errmsg = dbPoll( character, -1 ) dbPoll = results > query or free -_-"
Oxsotus Posted June 21, 2013 Author Posted June 21, 2013 I don't understand, what do you want to say. Sorry
iPrestege Posted June 21, 2013 Posted June 21, 2013 Use this and try : local result, row, errmsg = dbPoll( character, -1 ) P.S : What is your language?
Oxsotus Posted June 21, 2013 Author Posted June 21, 2013 http://kepfeltoltes.hu/130621/110780241 ... es.hu_.jpg Hungarian
Castillo Posted June 21, 2013 Posted June 21, 2013 I don't understand, what I need to post.You mean, to remove the username and password, like this: function login(player, command) local qh = dbConnect ( "mysql", "localhost" , "root", "" ) if(qh) then outputChatBox("Connecting to database succesful!",player,0,255,0) end local character = dbQuery( qh, "SELECT `Username` FROM `players`") local result, row, errmsg = dbPoll( qh, -1 ) end addCommandHandler("test",login) (I translate the variables name's to english) No, I mean, you must define the database on dbConnect.
Oxsotus Posted June 21, 2013 Author Posted June 21, 2013 function login(player, command) local qh = dbConnect( "mysql", "dbname=mtarpg;host=127.0.0.1", "root", "") if(qh) then outputChatBox("Connecting to database succesful!",player,0,255,0) end local character = dbQuery( qh, "SELECT `Username` FROM `players`") local result, row, errmsg = dbPoll( character, -1 ) row_=tostring(row) outputChatBox(row_,player) end addCommandHandler("teszt",login) It works!!! Thanks!! local qh = dbConnect( "mysql", "dbname=mtarpg;host=127.0.0.1", "root", "")
TAPL Posted June 21, 2013 Posted June 21, 2013 Don't forget to read the note on the wiki. Note: Connecting and disconnecting many times can have a performance impact on the server. For optimal performance it is recommended that you use dbConnect only once when the resource starts, and share the connection element with the whole script.
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