Jump to content

Recommended Posts

Look this https://ibb.co/cfRLam I have problem with dpCore from Drift Paradise ;x

Database.lua

--- Основной модуль для работы с базой данных
-- @module dpCore.Database
-- @author Wherry

Database = {}
local dbConnection

--- Выполняет подключение к базе данных.
-- Для подключения используются параметры из DatabaseConfig
-- @treturn bool удалось ли подключиться к БД
function Database.connect()
    if isElement(dbConnection) then
        outputDebugString("WARNING: Database.connect: connection already exists")
        return false
    end

    local host = DatabaseUtils.prepareDatabaseOptionsString {
        host = DatabaseConfig.host,
        port = DatabaseConfig.port,
        dbname = DatabaseConfig.dbName
    }
    local options = DatabaseUtils.prepareDatabaseOptionsString(DatabaseConfig.options)    
    dbConnection = Connection(
        DatabaseConfig.dbType,
        host,
        DatabaseConfig.username,
        DatabaseConfig.password,
        options
    )
    if not dbConnection then
        outputDebugString("ERROR: Database.connect: failed to connect")
        root:setData("dbConnected", false)
        return false
    end
    root:setData("dbConnected", true)
    return true
end

--- Возвращает MTA-элемент подключения к БД
-- @treturn element подключение 
function Database.getConnection()
    if not isElement(dbConnection) then
        dbConnection = nil
    end
    return dbConnection
end

--- Отключается от базы данных
-- @treturn bool удалось ли отключиться от база данных
function Database.disconnect()
    if not isElement(dbConnection) then
        outputDebugString("WARNING: Database.disconnect: no connection")
        return false
    end
    dbConnection:destroy()
    dbConnection = nil
    return true
end

Edited by Nismo_Gleichu
Link to comment
  • Administrators

Hey guys, look at this random chunk of code. Can you try and decipher what problem I'm having without giving you any information whatsoever?

First of all it might help to tell us what exactly the problem is.

What errors are you getting? Where are your database connection details?

Edited by LopSided_
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...