Jump to content

mySQL, dbPoll problem


Oxsotus

Recommended Posts

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

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
  
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
  
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

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
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
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
  
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!! :D

  
local  qh = dbConnect( "mysql", "dbname=mtarpg;host=127.0.0.1", "root", "") 
  

Link to comment

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...