Query Mysql R7
#1

Hi everybody,i need someone to help me in how i make a query with mysql R7?
I tried to read tutorials but i dont understand.
Let's say we want to extract the row "username", how i do that?
and explain please the code

Thanks very much
Reply
#2

SELECT `username` FROM `Table` WHERE `username` = 'name'

Try to look on w3schools or other sites, you will understand easy.
Reply
#3

pawn Код:
#define SQL_Host "127.0.0.1"
#define SQL_User "root"
#define SQL_Password ""
#define SQL_Database "yourdatabase"
new Connect_Handle;
forward OnAccountCheck;

public OnGamemodeInit()
{
    SQL_Start();
}

public OnPlayerConnect(playerid)
{
    new Query[200]; //Declare a Query, you could work out the exact length but I've put 200 just for demonstration
    format(Query, sizeof(Query), "SELECT `username` FROM `accounts` WHERE `username` = '%s'", GetName(playerid)); //Using a custom GetName stock
    mysql_function_query(Connect_Handle, Query, true, "OnAccountCheck", "d", playerid);
    return 1;
}

public OnAccountCheck(playerid)
{
    new rows;
    cache_get_data(rows, Connect_Handle);
    if(!rows)
    {
        //Doesn't find anything
    }
    else
    {
        //Finds something
    }
    return 1;
}

stock SQL_Start()
{
    Connect_Handle = mysql_connect(SQL_Host, SQL_User, SQL_Database, SQL_Password);
    return 1;
}
I just gave a quick and simple example of basically checking if a player is registered.
Reply
#4

Quote:
Originally Posted by Finn707
Посмотреть сообщение
pawn Код:
#define SQL_Host "127.0.0.1"
#define SQL_User "root"
#define SQL_Password ""
#define SQL_Database "yourdatabase"
new Connect_Handle;
forward OnAccountCheck;

public OnGamemodeInit()
{
    SQL_Start();
}

public OnPlayerConnect(playerid)
{
    new Query[200]; //Declare a Query, you could work out the exact length but I've put 200 just for demonstration
    format(Query, sizeof(Query), "SELECT `username` FROM `accounts` WHERE `username` = '%s'", GetName(playerid)); //Using a custom GetName stock
    mysql_function_query(Connect_Handle, Query, true, "OnAccountCheck", "d", playerid);
    return 1;
}

public OnAccountCheck(playerid)
{
    new rows;
    cache_get_data(rows, Connect_Handle);
    if(!rows)
    {
        //Doesn't find anything
    }
    else
    {
        //Finds something
    }
    return 1;
}

stock SQL_Start()
{
    Connect_Handle = mysql_connect(SQL_Host, SQL_User, SQL_Database, SQL_Password);
    return 1;
}
I just gave a quick and simple example of basically checking if a player is registered.
Thanks, but im reffering to " how to extract data from db" , the "rows" give you 1 or 0, i need the string.

I dont understand why i cannot use name to extract from db,only numbers.
Reply
#5

I strongly advise you to read this thread: https://sampforum.blast.hk/showthread.php?tid=337810, it explains all the new functions of R7 and newer versions and how to correctly use them.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)