Jump to content

MySQL script error!


Recommended Posts

Hello guys!

I wrote a script, for MySQL, and it's not working! What could be the problem?

Script:

  
local host = "127.0.0.1" 
local username = "root" 
local password = "" 
local db = "mta" 
local port = "3306" 
local results = {} 
  
addEventHandler("onResourceStart", resourceRoot, function() 
    dbHandler = dbConnect("mysql","dbname=".. db ..";host="..host, username, password, "autoreconnect=1") 
    if not dbHandler then 
        outputChatBox("#1 Mysql disconnecting...") 
        cancelEvent(true) 
    end 
end) 
  
function getMySQLUsername() 
    return username 
end 
  
function getMySQLPassword() 
    return password 
end 
  
function getMySQLDBName() 
    return db 
end 
  
function getMySQLHost() 
    return host 
end 
  
function getMySQLPort() 
    return port 
end 
  
function query_free(q,poll) 
    local this = #results + 1 
    results[this] = dbQuery(dbHandler, q) 
    if poll then 
        local result, num_affected_rows, last_insert_id = dbPoll(results[this], -1) 
        if result == nil then 
            dbFree(results[this]) 
            return this, nil 
        elseif result == false then 
            dbFree(results[this]) 
            return this, nil 
        else 
            dbFree(results[this]) 
            return this, tonumber(last_insert_id) 
        end 
    end 
    dbFree(results[this]) 
    return this 
end 
  
function getConnection() 
    return dbHandler 
end 
  
function singleQuery(str,...) 
    if (dbHandler) then 
        local query = dbQuery(dbHandler,str,...) 
        local result = dbPoll(query,-1) 
        if (type(result == "table")) then 
            return result[1] 
        else 
            return result 
        end 
    else 
        return false 
    end 
end 
  
function execute(str) 
    if (dbHandler) then 
        local query, id = query_free(str, true) 
        return query 
    else 
        return false 
    end 
end 
  
function getFreeResultPoolID() 
    return #results + 1 
end 
  
function escape_string(str) 
    if (str) then 
        return str 
    end 
    return false 
end 
  
function query_rows_assoc(str,...) 
    if (dbHandler) then 
        local this = #results + 1 
        results[this] = dbQuery(dbHandler, str, ...) 
        return dbPoll(results[this],-1) 
    else 
        return false 
    end 
end 
  
function query(str,...) 
    if (dbHandler) then 
        return query_rows_assoc(str,...) 
    else 
        return false 
    end 
end 
  
function query_fetch_assoc(str,...) 
    if(not str)then 
        return false 
    end 
    return singleQuery(str,...) 
end 
  
function query_insert_free(str) 
    if (dbHandler) then 
        local query, id = query_free(str, true) 
        return id 
    else 
        return false 
    end 
end 
  
function num_rows(result) 
    if(not result)then 
        return 0 
    end 
    if (type(result == "table")) then 
        return (#result or 0) 
    else 
        return 1 
    end 
end 

Debugscript:

[2016-03-06 17:10:22] WARNING: Script 'd_dbConnect/mysql.lua' is not encoded in UTF-8.  Loading as ANSI... 
[2016-03-06 17:10:22] SCRIPT ERROR: d_dbConnect/mysql.lua:1: unexpected symbol near '?' 
[2016-03-06 17:10:22] ERROR: Loading script failed: d_dbConnect/mysql.lua:1: unexpected symbol near '?' 

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