Sign in to follow this  
StefanAlmighty

MySQL help

Recommended Posts

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 

Share this post


Link to post
How can I do this in a client file?

no database for Server Side , not Client ,

you can use trigger

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post
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.

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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) 
  

Share this post


Link to post

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' 

Share this post


Link to post

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.

Share this post


Link to post

[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 
  

Share this post


Link to post

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.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.