cs8898 Posted March 17, 2013 Share Posted March 17, 2013 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
Jaysds1 Posted March 17, 2013 Share Posted March 17, 2013 (edited) 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 March 17, 2013 by Guest Link to comment
Anderl Posted March 17, 2013 Share Posted March 17, 2013 Seriously, how many times do I need to repeat this? Use local variables whenever possible. Link to comment
Anderl Posted March 17, 2013 Share Posted March 17, 2013 This page should tell you everything: http://www.coronalabs.com/blog/2011/07/ ... ables-lua/ Link to comment
cs8898 Posted March 27, 2013 Author Share Posted March 27, 2013 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
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