i made easy function - getAccountStorageValue(accid, key) and setAccountStorageValue(accid, key, value). : )
I'm using it in friend ots to events - one event per account ; )
Function for tfs 0.3b2
data/lib/function.lua
and to database:
Your,
azi.
I'm using it in friend ots to events - one event per account ; )
Function for tfs 0.3b2
data/lib/function.lua
PHP:
function getAccountStorageValue(accid, key)
local value = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = " .. accid .. " and `key` = " .. key .. " LIMIT 1;")
if(value:getID() ~= -1) then
return value:getDataInt("value")
else
return -1
end
value:free()
end
function setAccountStorageValue(accid, key, value)
local getvalue = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = " .. accid .. " and `key` = " .. key .. " LIMIT 1;")
if(getvalue:getID() ~= -1) then
db.executeQuery("UPDATE `account_storage` SET `value` = " .. accid .. " WHERE `key`=" .. key .. " LIMIT 1');")
getvalue:free()
return 1
else
db.executeQuery("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (" .. accid .. ", " .. key .. ", '"..value.."');")
return 1
end
end
and to database:
PHP:
CREATE TABLE `account_storage` (
`account_id` int(11) NOT NULL default '0',
`key` int(10) unsigned NOT NULL default '0',
`value` varchar(255) NOT NULL default '0',
UNIQUE KEY `account_id_2` (`account_id`,`key`),
KEY `account_id` (`account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Your,
azi.
Last edited: