MySQL R33+ (small help)
#1

hello, i've been trying to convert my mysql R5 gamemode to R33+.
I got stuck in this portion, how do i convert this to R33+

pawn Код:
new pname[24];
    GetPlayerName(playerid, pname, 24);
    format(query, sizeof(query), "SELECT `Banned` FROM `players` WHERE `user` = '%s' AND `Banned` = 1 LIMIT 1", pname);
    mysql_query(query);
    mysql_store_result();

    if(mysql_num_rows() != 0)//if number of rows is different from 0 then continue
    {
        ShowPlayerDialog(playerid, 2344, DIALOG_STYLE_MSGBOX,"Name is banned from the server","Your name is banned from the server!\n post it in the Unban appeals Category.","OK","");
        Kick(playerid);
    }
    mysql_free_result();
Reply
#2

Here you go:
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_tquery

Basically you're sending the query and you're calling a function when the query executes (successfully or not).
pawn Код:
mysql_tquery(connectionHandle, "SELECT Banned FROM players WHERE user = Bondage", "QueryResultCallback", "i", playerid); //passing the playerid as parameter to be able to send him a message if he's banned

public QueryResultCallback(playerid) //the only param of this function is playerid, which has been passed from the query
{
  //get the number of rows
  if(rows) // he's banned
  {
    //something - here you can use playerid to send the player a message and maybe kick him
  }
  else
  {
    //he's not banned - send a welcome message, call a login system if required etc
  }
}
Looks like there are 2 ways of getting the number of rows. Maybe there are more, but I only found these two:
[1] https://sampwiki.blast.hk/wiki/MySQL/R33..._get_row_count
[2] https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_data
Reply
#3

Quote:
Originally Posted by HazardouS
Посмотреть сообщение
Here you go:
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_tquery

Basically you're sending the query and you're calling a function when the query executes (successfully or not).
pawn Код:
mysql_tquery(connectionHandle, "SELECT Banned FROM players WHERE user = Bondage", "QueryResultCallback", "i", playerid); //passing the playerid as parameter to be able to send him a message if he's banned

public QueryResultCallback(playerid) //the only param of this function is playerid, which has been passed from the query
{
  //get the number of rows
  if(rows) // he's banned
  {
    //something - here you can use playerid to send the player a message and maybe kick him
  }
  else
  {
    //he's not banned - send a welcome message, call a login system if required etc
  }
}
Looks like there are 2 ways of getting the number of rows. Maybe there are more, but I only found these two:
[1] https://sampwiki.blast.hk/wiki/MySQL/R33..._get_row_count
[2] https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_data
Is this work along with any versions above R33?
Reply
#4

bump
Reply
#5

Try with this:
pawn Код:
new pname[24];
    GetPlayerName(playerid, pname, 24);
    mysql_format(/*mysql connection*/, query, sizeof(query), "SELECT `Banned` FROM `players` WHERE `user` = '%s' AND `Banned` = 1 LIMIT 1", pname);
    mysql_tquery(/*mysql connection*/, query, "", "");

    new rows, fields;
    cache_get_data(rows, fields, /*mysql connection*/);
    if(rows)
    {
        ShowPlayerDialog(playerid, 2344, DIALOG_STYLE_MSGBOX,"Name is banned from the server","Your name is banned from the server!\n post it in the Unban appeals Category.","OK","");
        Kick(playerid);
    }
Reply
#6

Quote:
Originally Posted by bgedition
Посмотреть сообщение
Try with this:
pawn Код:
new pname[24];
    GetPlayerName(playerid, pname, 24);
    mysql_format(/*mysql connection*/, query, sizeof(query), "SELECT `Banned` FROM `players` WHERE `user` = '%s' AND `Banned` = 1 LIMIT 1", pname);
    mysql_tquery(/*mysql connection*/, query, "", "");

    new rows, fields;
    cache_get_data(rows, fields, /*mysql connection*/);
    if(rows)
    {
        ShowPlayerDialog(playerid, 2344, DIALOG_STYLE_MSGBOX,"Name is banned from the server","Your name is banned from the server!\n post it in the Unban appeals Category.","OK","");
        Kick(playerid);
    }
Can ya explain me what is that /*mysql connection*/ ?

pawn Код:
mysql_format(/*mysql connection*/, query, sizeof(query), "SELECT `Banned` FROM `players` WHERE `user` = '%s' AND `Banned` = 1 LIMIT 1", pname);
mysql_tquery(/*mysql connection*/, query, "", "");


cache_get_data(rows, fields, /*mysql connection*/);
Actually i'm using this in place of that, is there anything wrong with it?

pawn Код:
static mysql; //i'm using this
mysql_format(mysql, query, sizeof(query), "SELECT `Banned` FROM `players` WHERE `user` = '%s' AND `Banned` = 1 LIMIT 1", pname);
mysql_tquery(mysql, query, "", "");


cache_get_data(rows, fields, mysql);
Reply
#7

The "mysql connection" thing, which i called connectionHandle, is the value returned by the mysql_connect function (https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_connect). You need to connect to a database before running any query.

I'm not sure if what bgedition wrote there actually works, you'll have to test it. I have my doubts, because as far as I know, the cache functions will return the correct values only if they are somehow related to the "parent" query, so they must be used within a callback which is called by that query, as I wrote in my example (the QueryResultCallback thing).

Regarding other versions, I guess this should work on them too, because I see some R35, R36 references on the wiki page. Also, there is this paragraph at the top of the page:
Quote:

Documentation for BlueG's MySQL plugin version R33 and later.

Reply
#8

Quote:
Originally Posted by HazardouS
Посмотреть сообщение
The "mysql connection" thing, which i called connectionHandle, is the value returned by the mysql_connect function (https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_connect). You need to connect to a database before running any query.

I'm not sure if what bgedition wrote there actually works, you'll have to test it. I have my doubts, because as far as I know, the cache functions will return the correct values only if they are somehow related to the "parent" query, so they must be used within a callback which is called by that query, as I wrote in my example (the QueryResultCallback thing).

Regarding other versions, I guess this should work on them too, because I see some R35, R36 references on the wiki page. Also, there is this paragraph at the top of the page:
Thanks buddy +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)