Azaroth Posted August 17, 2012 Share Posted August 17, 2012 Hello. How to get value from MySQL Databasa? I tried mysql_query and mysql_fetch_field. mysql_query returns: MySQL result (#32) and mysql_fetch_field return field name. Link to comment
AMARANT Posted August 17, 2012 Share Posted August 17, 2012 These functions might be useful for you: https://wiki.multitheftauto.com/wiki/DbQuery https://wiki.multitheftauto.com/wiki/DbPoll Link to comment
Azaroth Posted August 17, 2012 Author Share Posted August 17, 2012 It's SQL, not MySQL. Will it work? Link to comment
Castillo Posted August 17, 2012 Share Posted August 17, 2012 These functions can be used for both: SQLite and MySQL. Link to comment
Azaroth Posted August 17, 2012 Author Share Posted August 17, 2012 local query = dbQuery( handler, "SELECT * FROM pickups" ) It's not working. I get warning: Bad argument @ 'dbQuery' [Expected db-connection at argument 1, got userdata] Link to comment
AMARANT Posted August 17, 2012 Share Posted August 17, 2012 You have to open a connection with your database in order to start a query. https://wiki.multitheftauto.com/wiki/DbConnect Link to comment
Azaroth Posted August 17, 2012 Author Share Posted August 17, 2012 It's connected with mysql_connect. handler = mysql_connect("localhost", "root", "pass", "multi theft auto") @EDIT: Ok. Connected with DbConnect and got values with dbPoll, but I don't understand that dbPoll. Can someone explain me how it works? local query = dbQuery( connection, "SELECT * FROM pickups WHERE UID="..i) local result, numrows, errmsg = dbPoll ( query, -1 ) if numrows > 0 then 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 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