MySQL how to insert data? -
PaulDinam - 07.02.2013
Title says all.
Re: MySQL how to insert data? -
Scenario - 07.02.2013
http://dev.mysql.com/doc/refman/5.5/en/insert.html
Код:
INSERT INTO tbl_name () VALUES();
Re: MySQL how to insert data? -
PaulDinam - 07.02.2013
... I know how to insert...
this is what I thought would be okay:
Код:
getdate(year, month, day);
format(data, sizeof(data), "%d-%d-%d", day, month, year);
format(query, sizeof(query), "INSERT INTO `kicks` (player, victim, reason, data) VALUES ('%s', '%s', '%s', '%s')", GetName(playerid), GetName(id), reason, data);
Re: MySQL how to insert data? -
Scenario - 07.02.2013
That should work fine...
Re: MySQL how to insert data? -
Meta - 07.02.2013
I'd suggest only saving the timestamp instead of calculated values. You can do anything with timestamps later (in PHP fot example (it's not that easy in pawn)).
Re: MySQL how to insert data? -
Scenario - 07.02.2013
Quote:
Originally Posted by Meta
it's not that easy in pawn
|
Sure it is!
Here's a snippet from a temp-ban system I wrote using time-stamps.
pawn Код:
new szIP[16], szUsername[26], szAdminName[26], szReason[60], temp[20];
cache_get_row(0, 0, temp);
new iBanID = strval(temp);
cache_get_row(0, 1, szIP);
cache_get_row(0, 2, szUsername);
cache_get_row(0, 3, szAdminName);
cache_get_row(0, 4, szReason);
cache_get_row(0, 5, temp);
new iBannedTimestamp = strval(temp);
cache_get_row(0, 6, temp);
new iUnbannedTimestamp = strval(temp);
if(gettime() >= iUnbannedTimestamp)
{
new szQuery[128];
format(szQuery, sizeof(szQuery), "DELETE FROM `Bans` WHERE `banID` = %d", iBanID);
mysql_function_query(connectionHandle, szQuery, false, "databaseCallback", "");
format(szQuery, sizeof(szQuery), "SELECT * FROM `Accounts` WHERE `Username` = '%s'", getEscName(playerid));
mysql_function_query(connectionHandle, szQuery, true, "accountCheck", "d", playerid);
}
else
{
clearPlayerChat(playerid);
new szString[128];
SendClientMessage(playerid, COLOR_RED, "You are banned from this server.");
SendClientMessage(playerid, -1, " ");
format(szString, sizeof(szString), "You were banned by {E70000}%s {FFFFFF}on %s.", szAdminName, date(iBannedTimestamp, 2));
SendClientMessage(playerid, COLOR_WHITE, szString);
format(szString, sizeof(szString), "Reason: %s", szReason);
SendClientMessage(playerid, COLOR_WHITE, szString);
SendClientMessage(playerid, -1, " ");
format(szString, sizeof(szString), "You will be automatically unbanned on %s.", date(iUnbannedTimestamp, 2));
SendClientMessage(playerid, COLOR_WHITE, szString);
defer serverKickDelay(playerid);
}
When the account/IP is banned, it adds a time-stamp into the table with the calculations already added (i.e. how many days, weeks, months, years, etc). I can load this time-stamp and compare it to gettime() to see if the person should be un-banned.
Either way, that's off topic. Using time-stamps is a better idea than how the OP is wanting to save the date, but that's his choice.
Re: MySQL how to insert data? -
Meta - 08.02.2013
Quote:
Originally Posted by RealCop228
Sure it is!
|
What I meant is converting a timestamp to a dayname, a month number or whatever and vice versa