Jump to content

MySQL Qery Error


cs8898

Recommended Posts

When i tried to get data from my sql Server, i got an Table with one object but that objects is nil why?

could it be, that the sql Server istn't ready?

the code:

outputChatBox("halloWelt") 
rpg_db = dbConnect("mysql","dbname=mta_rpg;host=127.0.0.1","***","****") -- ***=uname ****=password 
if not rpg_db then 
outputConsole ("failed") 
end 
outputChatBox("loaded") 
q = dbQuery(rpg_db,"SELECT fname FROM acc") 
res = dbPoll(q,-1) 
outputChatBox(table.getn(res[1])) 
--for i = 1,table.getn(res) do 
--  outputChatBox( res[i][1]..":"..res[i][2]..":"..res[i][3]) 
  
--end 
outputChatBox("mysqlQery") 
  

Link to comment

If the MySQL server wasn't running, then the connection would fail and it would've output that the server could not be reached.

Anyways, It looks like your MySQL server is running on your computer because 127.0.0.1 is localhost.

try this:

outputChatBox("halloWelt") 
rpg_db = dbConnect("mysql","dbname=mta_rpg;host=**","***","****") -- **=host/ip ***=uname ****=password 
if not rpg_db then 
outputConsole ("failed") 
return --stops the script from continuing  
end 
outputChatBox("loaded") 
dbQuery(function(q) 
     res = dbPoll(q,-1) 
     --Got this from the wiki for you 
     for result, row in pairs ( result ) do 
          -- by using a second loop (use it if you want to get the values of all columns the query selected): 
          for column, value in pairs ( row ) do 
               -- column = the mysql column of the table in the query 
               -- value = the value of that column in this certain row 
          end 
          -- or without a second loop (use it if you want to handle every value in a special way): 
          outputChatBox ( row["column"] ) -- it will output the value of the column "column" in this certain row 
     end 
end,rpg_db,"SELECT fname FROM acc") 
outputChatBox("mysqlQery") 

Edited by Guest
Link to comment
  • 2 weeks later...

I know what you mena with the table i used table.getn() to show how many items are in the table but if i use table.getn(Table[1]) to see the second row, it answers 0 but if i want to get the variable table[1] it schows the error bekause it's nil, but the first has one data

@Anderl ther is no need of global/local variables

if i use table.concat() it answers "invalid value (table) at index 1 in table for 'concat'"

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