Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Developers:
- • .WhiteBlue (szymon.lua@gmail.com)
- Copyright (c) 2018 .WhiteBlue (szymon.lua@gmail.com)
- Note (EN): You can not copy and share this code without my permission.
- Note (PL): Nie możesz kopiować i udostępniać tego kodu bez mojej zgody.
- ]]
- -- Variables
- local connection = {
- element = nil,
- -- Database
- database = {
- ['host'] = '',
- ['name'] = '',
- ['username'] = '',
- ['password'] = '',
- },
- }
- -- Functions
- function database_get(type, ...)
- if not connection['element'] or not {...} then return nil end
- local prepare = dbPrepareString(connection['element'], ...)
- if prepare then
- local query = dbQuery(connection['element'], prepare)
- local result, num_affected_rows, last_insert_id = dbPoll(query, -1)
- if result and num_affected_rows and last_insert_id then
- if type then
- if type == 'one' then
- return result[1], num_affected_rows, last_insert_id
- elseif type == 'more' then
- return result, num_affected_rows, last_insert_id
- end
- end
- end
- end
- end
- function database_set(...)
- if not connection['element'] or not {...} then return nil end
- local prepare = dbPrepareString(connection['element'], ...)
- if prepare then
- local query = dbExec(connection['element'], prepare)
- if query then
- return true
- else
- return nil
- end
- end
- end
- addEventHandler('onResourceStart', resourceRoot,
- function()
- if not connection['database'] then return nil end
- if not connection['database']['host'] or connection['database']['host'] == 0 then
- outputDebugString('(og-connection/connection.lua) ✗ Nie znaleziono hosta bazy danych.')
- return nil
- end
- if not connection['database']['name'] or connection['database']['name'] == 0 then
- outputDebugString('(og-connection/connection.lua) ✗ Nie znaleziono nazwy bazy danych.')
- return nil
- end
- if not connection['database']['username'] or connection['database']['username'] == 0 then
- outputDebugString('(og-connection/connection.lua) ✗ Nie znaleziono użytkownika bazy danych.')
- return nil
- end
- if not connection['database']['password'] or connection['database']['password'] == 0 then
- outputDebugString('(og-connection/connection.lua) ✗ Nie znaleziono hasła użytkownika bazy danych.')
- return nil
- end
- -- Connect
- local connect = dbConnect('mysql', 'host='.. connection['database']['host'] ..';dbname='.. connection['database']['name'] ..';charset=utf8', connection['database']['username'], connection['database']['password'], 'share=1')
- if connect then
- connection['element'] = connect
- outputDebugString('(og-connection/connection.lua) ✓ Nawiązano połączenie z bazą danych.')
- else
- connection['element'] = nil
- outputDebugString('(og-connection/connection.lua) ✗ Nie nawiązano połączenia z bazą danych.')
- end
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement