SA-MP Forums Archive
Help to covert this PHP to PAWN (MYSQL) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Server (https://sampforum.blast.hk/forumdisplay.php?fid=6)
+--- Forum: Server Support (https://sampforum.blast.hk/forumdisplay.php?fid=19)
+--- Thread: Help to covert this PHP to PAWN (MYSQL) (/showthread.php?tid=609582)



Help to covert this PHP to PAWN (MYSQL) - maikons - 14.06.2016

Someone could help me to finish convert this script PHP to PAWN SAMP?

I want put it ongamemodeinit to clean my DB

PHP script base:
Код:
 <?php
    $link = mysql_connect('IP', 'User', 'Pass');
    mysql_select_db('DB', $link);

    $EXP = array(
        50,
        100,
        250,
        500
    );
    $TEMPO = array(
        15 * 86400,
        30 * 86400,
        90 * 86400,
        120 * 86400,
        360 * 86400
    );
    $query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " . $TEMPO[1] .") AND `experience` <=" . $EXP[1];
    mysql_query($query);
    $num = mysql_affected_rows();
    echo "$num rows deletadas que nгo logaram nos ultimos 15 dias, com experiencia menor que 50";
    $query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " . $TEMPO[2] .") AND `experience` <=" . $EXP[2];
    mysql_query($query);
    $num = mysql_affected_rows();
    echo "$num rows deletadas que nгo logaram nos ultimos 30 dias, com experiencia menor que 100";
    $query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " . $TEMPO[3] .") AND `experience` <=" . $EXP[3];
    mysql_query($query);
    $num = mysql_affected_rows();
    echo "$num rows deletadas que nгo logaram nos ultimos 90 dias, com experiencia menor que 250";
    $query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " . $TEMPO[4] .") AND `experience` <=" . $EXP[4];
    mysql_query($query);
    $num = mysql_affected_rows();
    echo "$num rows deletadas que nгo logaram nos ultimos 120 dias, com experiencia menor que 500";
    $query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " . $TEMPO[5] .")";
    mysql_query($query);
    $num = mysql_affected_rows();
    echo "$num rows deletadas que nгo logaram nos ultimos 360 dias, com qualquer experiencia";
My pawn try
Код:
foward CleanDB(); public CleanDB() {
    new EXP[4];
    EXP[1] = 20;
    EXP[2] = 100;
    EXP[3] = 500;

    new TEMPO[5];
    TEMPO[1] = 90 * 86400;
    TEMPO[2] = 120 * 86400;
    TEMPO[3] = 300 * 86400;
    TEMPO[4] = 360 * 86400;

    new query[128], num;

    query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " , TEMPO[1] .") AND `experience` <=" , EXP[1];
    mysql_query(query);
    num = mysql_affected_rows();
    print("num rows was ben deleted because inactivity (90 days / exp 20-)");


    query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " , TEMPO[2] .") AND `experience` <=" , EXP[2];
    mysql_query(query);
    num = mysql_affected_rows();
    print("num rows was ben deleted because inactivity (120 days / exp 100-)");


    query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " , TEMPO[3] .") AND `experience` <=" , EXP[3];
    mysql_query(query);
    num = mysql_affected_rows();
    print("num rows was ben deleted because inactivity (300 days / exp 500-)");


    query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " , TEMPO[4] .")";
    mysql_query(query);
    num = mysql_affected_rows();
    print("num rows was ben deleted because inactivity (360 days / exp 501+)");
}



Re: Help to covert this PHP to PAWN (MYSQL) - maikons - 16.06.2016

bump


Re: Help to covert this PHP to PAWN (MYSQL) - iKarim - 16.06.2016

You can't define variables using '$' like in PHP. Both are different languages I don't really know why did you copy-paste from PHP to PAWN. Also, you don't need to forward (define publicly) functions.


Re: Help to covert this PHP to PAWN (MYSQL) - maikons - 16.06.2016

Quote:
Originally Posted by PawnHunter
Посмотреть сообщение
You can't define variables using '$' like in PHP. Both are different languages I don't really know why did you copy-paste from PHP to PAWN. Also, you don't need to forward (define publicly) functions.
ty +rep

idk much about PHP/MYSQL but i need to do it...

i edit the topic..
someone could tell me if i made right to clean inactives account or have something worng?


Re: Help to covert this PHP to PAWN (MYSQL) - maikons - 17.06.2016

I've tried it:
Код:
forward CleanDB(); public CleanDB() {
    new EXP[4];
    EXP[1] = 20;
    EXP[2] = 100;
    EXP[3] = 500;

    new TEMPO[5];
    TEMPO[1] = 90 * 86400;
    TEMPO[2] = 120 * 86400;
    TEMPO[3] = 300 * 86400;
    TEMPO[4] = 360 * 86400;

    new query[128], num;
    format(query, sizeof(query), "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + %d) AND `experience` <= %d" , TEMPO[1], EXP[1]);
    query = mysql_query(query);  // error 035: argument type mismatch (argument 1) && error 033: array must be indexed (variable "query")
    num = mysql_affected_rows(); // error 017: undefined symbol "mysql_affected_rows"
    printf("%d rows was ben deleted because inactivity (90 days / exp 20-)", num);


    query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " , TEMPO[2] .") AND `experience` <=" , EXP[2]; // warning 215: expression has no effect && error 001: expected token: ";", but found "." && error 029: invalid expression, assumed zero
    format(query, sizeof(query), "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + %d) AND `experience` <= %d" , TEMPO[2], EXP[2]);
    mysql_query(query); // error 035: argument type mismatch (argument 1)
	num = mysql_affected_rows(); // error 017: undefined symbol "mysql_affected_rows"
    printf("%d rows was ben deleted because inactivity (120 days / exp 100-)", num);


    format(query, sizeof(query), "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + %d) AND `experience` <= %d" , TEMPO[3], EXP[3]);
    mysql_query(query); // error 035: argument type mismatch (argument 1)
    num = mysql_affected_rows(); // error 017: undefined symbol "mysql_affected_rows"
    printf("%d rows was ben deleted because inactivity (300 days / exp 500-)", num);

    format(query, sizeof(query), "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + %d)", TEMPO[4]);
    mysql_query(query); // error 035: argument type mismatch (argument 1)
    num = mysql_affected_rows(); // error 017: undefined symbol "mysql_affected_rows"
    printf("%d rows was ben deleted because inactivity (360 days / exp 501+)", num);
}
But give me some errors
( i putted errors in code after // )


Re: Help to covert this PHP to PAWN (MYSQL) - maikons - 23.06.2016

up!!!!!!!!!!!!


Re: Help to covert this PHP to PAWN (MYSQL) - Arturo226 - 02.07.2016

Код:
    new EXP[4];
    EXP[1] = 20;
    EXP[2] = 100;
    EXP[3] = 500;
Array index starts from 0 and ends at (size of array - 1).
Код:
    query = mysql_query(query);  // error 035: argument type mismatch (argument 1) && error 033: array must be indexed (variable "query")
query is of type string, not sure what you're trying to do there. Just call the function?
Код:
    num = mysql_affected_rows(); // error 017: undefined symbol "mysql_affected_rows"
Function doesn't exist?
Код:
    query = "DELETE * FROM `accounts` WHERE `lastlogin` UNIX_TIMESTAMP() >= (`lastlogin` + " , TEMPO[2] .") AND `experience` <=" , EXP[2]; // warning 215: expression has no effect && error 001: expected token: ";", but found "." && error 029: invalid expression, assumed zero
Not needed.