Jump to content

Help me with database


MarvelSK

Recommended Posts

Hello I need really help, I have got script for DB and I don´t know how to connect it with my database dbadmin.sk here is script 

Spoiler

DBHandler=nil
DBName="236050_mysql_db"
DBUser="236050_mysql_db"
DBPass="///" 
DBHost="82.208.17.10"

-- Functions
function dbSet(...)
    if not {...} then return end
    local stringe=dbPrepareString(DBHandler,...)
    local query=dbExec(DBHandler, stringe)
    return query
end

function dbGet(...)
    if not {...} then return end
    local stringe=dbPrepareString(DBHandler,...)
    local query=dbQuery(DBHandler, stringe)
    local result=dbPoll(query, -1)
    return result
end


addEventHandler("onResourceStart", resourceRoot, function()
    DBHandler=dbConnect("mysql", "dbname="..DBName..";host="..DBHost.."", DBUser, DBPass, "share=1;autoreconnect=1")
    if DBHandler then
        outputDebugString("* Connect to server MYSQL...")
        dbSet("SET NAMES utf8")
    else
        outputDebugString("* No Connecting to server MYSQL..")
    end
end)


local SQL_LOGIN="236050_mysql_db"
local SQL_PASSWD="///"
local SQL_DB="236050_mysql_db"
local SQL_HOST="82.208.17.10"
local SQL_PORT=3306

local root = getRootElement()

local SQL

local function connect()
    SQL = mysql_connect(SQL_HOST, SQL_LOGIN, SQL_PASSWD, SQL_DB, SQL_PORT)
    if (not SQL) then
        outputServerLog("BRAK POLACZENIA Z BAZA DANYCH!")
    else
        --mysql_query(SQL,"SET NAMES utf8")
        --outputServerLog("Modul mysql polaczony!")
    end

end


local function keepAlive()
    if (not mysql_ping(SQL)) then
        outputServerLog("Zerwane polaczenie z baza danych, nawiazywanie...")
        connect()
    end
end
addEventHandler("onResourceStart",getResourceRootElement(),function()
    connect()
    setTimer(keepAlive, 30000, 0)
end)

function esc(value)
    return mysql_escape_string(SQL,value)
end

function pobierzTabeleWynikow(query)
    local result=mysql_query(SQL,query)
    if (not result) then 
        outputDebugString("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL))
        outputServerLog("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL))
        return nil 
    end
    local tabela={}
    for result,row in mysql_rows_assoc(result) do
        table.insert(tabela,row)
    end
    mysql_free_result(result)
    return tabela
end

function pobierzWyniki(query)
    local result=mysql_query(SQL,query)
    if (not result) then return nil end
    row = mysql_fetch_assoc(result)
    mysql_free_result(result)
    return row
end


function zapytanie(query)
    local result=mysql_query(SQL,query)
    if (result) then mysql_free_result(result) return true end
    return
end

function insertID()
    return mysql_insert_id(SQL)
end

function affectedRows()
    return mysql_affected_rows(SQL)
end


function fetchRows(query)
    local result=mysql_query(SQL,query)
    if (not result) then return nil end
    local tabela={}

    while true do
        local row = mysql_fetch_row(result)
        if (not row) then break end
        table.insert(tabela,row)
    end
    mysql_free_result(result)
    return tabela
end


function getSQLLink()
    return SQL
end

and how to connect it for database this is script in my server files but for example I go to shop and I bought a new car and in debugscript 3 is ERROR DATABASE and more HELP ME

Edited by MarvelSK
Link to comment
29 minutes ago, MarvelSK said:

That database can not be in first line and more I give you account and FTP and you can repair it 

That's not how community works :D

Post screenshot of all errors and people will try to help you understand what the problem is so you can fix it yourself (or atleast try to). :)

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