Query Mysql R7 - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Query Mysql R7 (
/showthread.php?tid=441644)
Query Mysql R7 -
cristip - 03.06.2013
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
Re: Query Mysql R7 -
IstuntmanI - 03.06.2013
SELECT `username` FROM `Table` WHERE `username` = 'name'
Try to look on w3schools or other sites, you will understand easy.
Re: Query Mysql R7 -
Finn707 - 03.06.2013
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.
Re: Query Mysql R7 -
cristip - 03.06.2013
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.
Re: Query Mysql R7 -
Finn707 - 03.06.2013
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.