Szerző Téma: MySQL - Mi a különbség és mit szolgál?  (Megtekintve 1073 alkalommal)

MySQL - Mi a különbség és mit szolgál?
« Dátum: 2017. február 21. - 10:12:53 »
0 Show voters
1. esetben
 

local sqlDatas = {
[\"host\"] = \"localhost\",
[\"user\"] = \"root\",
[\"pw\"] = \"\",
[\"database\"] = \"mta_2017\",
}
local results = {}
function getSQLDatas()
return sqlDatas
end
addEventHandler(\"onResourceStart\", resourceRoot, function()
dbHandler = dbConnect(\"mysql\",\"dbname=\".. sqlDatas[\"database\"] ..\";host=\"..sqlDatas[\"host\"], sqlDatas[\"user\"], sqlDatas[\"pw\"], \"autoreconnect=1\")
if not dbHandler then
   outputChatBox(\"Nem sikerült csatlakozni az adatbázishoz!\")
   cancelEvent(true)
end
end)
function getConnection()
return dbHandler
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

 
 
 
2. esetben
 

local hostname = \"localhost\"
local username = \"root\"
local password = \"\"
local database = \"mta_2017\"
local results = {}
addEventHandler(\"onResourceStart\", resourceRoot, function()
dbHandler = dbConnect(\"mysql\",\"dbname=\".. database ..\";host=\"..hostname, username, password, \"autoreconnect=1\")
if not dbHandler then
   outputChatBox(\"Nem sikerült csatlakozni az adatbázishoz!\")
   cancelEvent(true)
end
end)
function escape_string(str)
if str then
   return tostring(str)
else
   return \"false\"
end
end
function query_free(q)
local this = #results + 1
results[this] = dbQuery( dbHandler, q )
dbFree(results[this])
return this
end
function getConnection()
return dbHandler
end

 
 

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal