StefanAlmighty Posted September 16, 2015 Share Posted September 16, 2015 How would I go about checking if a row exists in my database in my script? And if it does exist, return true? Link to comment
JR10 Posted September 16, 2015 Share Posted September 16, 2015 There are many ways to do this. Most simple is probably: dbQuery(callback, database, 'SELECT 1 FROM `table` WHERE ... LIMIT 1') function callback(qh) local result = dbPoll(qh, 0) if (#result > 0) -- it exists end end Link to comment
StefanAlmighty Posted September 16, 2015 Author Share Posted September 16, 2015 How can I do this in a client file? Link to comment
LoOs Posted September 16, 2015 Share Posted September 16, 2015 How can I do this in a client file? no database for Server Side , not Client , you can use trigger Link to comment
StefanAlmighty Posted September 16, 2015 Author Share Posted September 16, 2015 One more thing, how do I update my server from MTA 1.4 to MTA 1.5? Link to comment
JR10 Posted September 17, 2015 Share Posted September 17, 2015 You can do an in-place upgrade by replacing the files. If it's on windows, simply running the installer would do. If this is on Linux, just replace the files with the newer ones. Link to comment
StefanAlmighty Posted September 17, 2015 Author Share Posted September 17, 2015 Where can I get this installer? And yes, it's windows. Link to comment
StefanAlmighty Posted September 17, 2015 Author Share Posted September 17, 2015 Alright so I've done it, but when I boot up the server is says "error parsing config file" and then closes. Link to comment
StefanAlmighty Posted September 17, 2015 Author Share Posted September 17, 2015 I managed to fix that issue, however now, when I start up the server none of my MySQL is working. It just gives off a bunch of errors. Link to comment
StefanAlmighty Posted September 18, 2015 Author Share Posted September 18, 2015 ERROR: MySQL\mysql_connect.lua:235: attempt to call global `MySQL_ping` (a nil value) ERROR: doors\server_doors.lua:217: call: failed to call `MySQL:query` [string "?"] ^ the console just repeats these exact errors but for different resources, such as "gangs-system". They worked fine on 1.4, but as soon as I converted to 1.5, I got these errors. Link to comment
Moderators Citizen Posted September 18, 2015 Moderators Share Posted September 18, 2015 ERROR: MySQL\mysql_connect.lua:235: attempt to call global `MySQL_ping` (a nil value) I don't know how it could work on 1.4 because the function name is mysql_ping not MySQL_ping. ERROR: doors\server_doors.lua:217: call: failed to call `MySQL:query` [string "?"] I'm not really sure but it can be produced by the first error. Fix the first one and see if it's still there. Link to comment
StefanAlmighty Posted September 18, 2015 Author Share Posted September 18, 2015 I just fixed the mysql_ping and I still get those errors. EDIT: The server does boot up and you can connect, but MySQL doesn't work at all which means I can't login because it can't fetch my account details from my DB. Link to comment
Moderators Citizen Posted September 18, 2015 Moderators Share Posted September 18, 2015 Can you provide some code where the errors occurs ? For example the doors\server_doors.lua:217 (but do not show only that line, if you can paste the whole function, it will be better). Link to comment
StefanAlmighty Posted September 18, 2015 Author Share Posted September 18, 2015 I don't get this error just in doors\server_doors.lua:217, I get it in like every single script which uses MySQL. I think there's an issue with MySQL connecting to all the resources but I'm not sure what it is. Link to comment
JR10 Posted September 18, 2015 Share Posted September 18, 2015 The second error is output because call fails to execute your exported function, either the resource is not started or the function is not exported. Make sure that the function is exported server-side. Link to comment
StefanAlmighty Posted September 18, 2015 Author Share Posted September 18, 2015 The resource automatically starts in my mtaserver.config and the function is exported because it works perfectly in 1.4 (I double checked in MySQL/meta.xml too). I only get these issues because of the transition between 1.4 and 1.5. I just noticed another error in the console, so all three are: ERROR: mysql\connection.lua:235: attempt t9 call global 'mysql_ping' (a nil value) ERROR: doors\server_doors.lua:217: call: failed to call `MySQL:query` [string "?"] ERROR: npcs\server_npcs.lua:14: attempt to call global 'mysql_null' (a nil value) Link to comment
Moderators Citizen Posted September 18, 2015 Moderators Share Posted September 18, 2015 Sounds like the MTA-MySQL module is missing/got deleted by your migration. Try to reinstall it: https://wiki.multitheftauto.com/wiki/Modules/MTA-MySQL EDIT: or there is no <module src="mta_mysql.dll" /> anymore in your mtaserver.conf. Link to comment
StefanAlmighty Posted September 18, 2015 Author Share Posted September 18, 2015 That fixed it, thanks. Last thing, I'm getting a few issues where it says "access denied". I'm getting that from a few different resources. For example, I have an in-game command called "setpw" which sets the servers password. I type it and nothing happens, but on the console it says: WARNING: admin\admin_commands.lua:68: Access denied @ 'setServerPassword' Link to comment
Moderators Citizen Posted September 18, 2015 Moderators Share Posted September 18, 2015 You have to add the resource into the Admin group in your acl.xml (he surely got replaced when you did your migration so that resource is not in that group anymore). Only add resources you trust in that group and shutdown the server before manually editing acl.xml. Link to comment
StefanAlmighty Posted September 18, 2015 Author Share Posted September 18, 2015 All done. Thanks! Link to comment
StefanAlmighty Posted September 18, 2015 Author Share Posted September 18, 2015 [After running my server it gives an error in the console which seems to effect a few things in-game. WARNING: global\server_accounts.lua:24: getCharacterNameFromID(): Unable The function causing the issue: function getCharacterNameFromID(charID) if not charID then return false end local query = exports.mysql:query_fetch_assoc("SELECT `charactername` FROM characters WHERE `id`='"..exports.mysql:escape_string(charID).."' LIMIT 1") if query then local charName = tostring(query["charactername"]) exports.mysql:free_result(query) if charName then return charName end end outputDebugString("getCharacterNameFromID(): Unable",2) return false end It's exported in the mysql meta.xml so here's the code for the getCharacterNameFromID function query_rows_assoc(str) local queryresult = query(str) if not (queryresult == false) then local result = rows_assoc(queryresult) free_result(queryresult) return result end return false end Link to comment
Moderators Citizen Posted September 18, 2015 Moderators Share Posted September 18, 2015 Make sure that the table characters exists in your database and that there are datas in it. Your script is probably calling at some point getCharacterNameFromID(x) where x is the id of the character in the table but if x is for example 4 and that there are only 1, 2 and 3 in the table, then it will throw the same error. Link to comment
StefanAlmighty Posted September 18, 2015 Author Share Posted September 18, 2015 Yeah, fixed, thanks very much. 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