MySQL how to insert data?
#1

Title says all.
Reply
#2

http://dev.mysql.com/doc/refman/5.5/en/insert.html

Код:
INSERT INTO tbl_name () VALUES();
Reply
#3

... 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);
Reply
#4

That should work fine...
Reply
#5

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)).
Reply
#6

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.
Reply
#7

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
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)