Oxsotus Posted June 21, 2013 Share 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. Link to comment
iPrestege Posted June 21, 2013 Share 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 . Link to comment
Oxsotus Posted June 21, 2013 Author Share 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. Link to comment
iPrestege Posted June 21, 2013 Share Posted June 21, 2013 You can't use the same variable. Link to comment
Oxsotus Posted June 21, 2013 Author Share 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 Link to comment
Vision Posted June 21, 2013 Share Posted June 21, 2013 Try to change this local result, row, errmsg = dbPoll( qh, -1 ) to this local result, row, errmsg = dbPoll ( character, -1 ) Link to comment
Oxsotus Posted June 21, 2013 Author Share Posted June 21, 2013 I changed, but now: WARNING: rpg\account_system_server.lua:35: dbPoll failed; No database selected Link to comment
Oxsotus Posted June 21, 2013 Author Share 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) Link to comment
Castillo Posted June 21, 2013 Share Posted June 21, 2013 Post the arguments you used for dbConnect, all of them, just remove password and user. Link to comment
Oxsotus Posted June 21, 2013 Author Share 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) Link to comment
iPrestege Posted June 21, 2013 Share 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 -_-" Link to comment
Oxsotus Posted June 21, 2013 Author Share Posted June 21, 2013 I don't understand, what do you want to say. Sorry Link to comment
iPrestege Posted June 21, 2013 Share Posted June 21, 2013 Use this and try : local result, row, errmsg = dbPoll( character, -1 ) P.S : What is your language? Link to comment
Oxsotus Posted June 21, 2013 Author Share Posted June 21, 2013 http://kepfeltoltes.hu/130621/110780241 ... es.hu_.jpg Hungarian Link to comment
Castillo Posted June 21, 2013 Share 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. Link to comment
Oxsotus Posted June 21, 2013 Author Share 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", "") Link to comment
TAPL Posted June 21, 2013 Share 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. 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