How can I converte my code with R7‘s mysql_function_query
#1

The new mysql plugin R7‘s mysql_function_query() makes me very confused.
Could any one please help me?

My old code is as follows:
Code:
public MySQLCheckAccount(name[]) 
{
	new query[128],id;
	mysql_real_escape_string(name, name);
	format(query, sizeof(query), "SELECT id FROM users WHERE `Name` = '%s' LIMIT 1", name);
	mysql_query(query);
	mysql_store_result();
	if (mysql_num_rows()==0) return 0;
	else
	{
		mysql_fetch_row(name);
		intid = strval(id);
		return id;
	}
}
When I faced with R7, mysql_query is not work
So I change the code to
Code:
public MySQLCheckAccount(name[]) 
{
	new query[128],id;
	mysql_real_escape_string(name, name);
	mysql_format(query, sizeof(query), "SELECT id FROM users WHERE `Name` = '%s' LIMIT 1", name);
	mysql_function_query(Handel,query,true,"onMySQLCheckAccount","","");
}
public onMySQLCheckAccount() 
{
        cache_get_row(0, 0, tmp), id= strval(tmp);
        return 1;
BUT HOW CAN I return the value "id" to where I'v called the MySQLCheckAccount(name) As the old code did????
}
BUT HOW CAN I return the value "id" to where I'v called the MySQLCheckAccount(name) As the old code did?
Reply
#2

Could any one please help me?
Reply
#3

Could any one please help me?
Thank you very much!
Reply
#4

Simply call onMySQLCheckAccount with a playerid parameter, and store the id in a global variable.

example
pawn Code:
new gSQLid[MAX_PLAYERS];

public MySQLCheckAccount(playerid)
{
    new
        query[128],
        name[MAX_PLAYER_NAME];
       
    GetPlayerName(playerid, name, sizeof(name));
    mysql_format(query, sizeof(query), "SELECT id FROM users WHERE `Name` = '%s' LIMIT 1", name);
    mysql_function_query(Handel, query, true,"onMySQLCheckAccount", "d", playerid);
    return 1;
}

public onMySQLCheckAccount(playerid)
{
    new tmp[30];
    cache_field_content(0, "id", tmp); // The second parameter here is your field name
    gSQLid[playerid] = strval(tmp);
    return 1;
}
Reply
#5

Thank you first, but this is not exactly what I want.
I need to take some values usualy from the mysql DB, so I write this as an function,so In the old version, I can use like this:
Code:
 id1=MySQLCheckAccount(name1);
id2=MySQLCheckAccount(name2);
num=id+id2;
....
...
but if I let id1 and id2 as global variable.

Code:
 
MySQLCheckAccount(name1);
MySQLCheckAccount(name2);
num=id1+id2; //when the code gose to here, id1 and id2 are still NULL,becaues the query takes times! 
but it very hard to write the following code into the callbacks, due to the complicated code. 
....
...
It realy makes me crazy!!!!!!!
Reply
#6

It's confusing, but what exactly are you trying to do with a player's row id (account id)
Reply
#7

Quote:
Originally Posted by VincentDunn
View Post
It's confusing, but what exactly are you trying to do with a player's row id (account id)
It's just a simplified example that meant to explain my case clearly to you.
My code is complicated, such as I need to count the rows of a table continuously, and feedbak the rows number, it is easy to do in the old version with mysql_query(), I don't know why to abandon this very useful function and makes the easy things so difficult!
NOT EVERY CASE IS SUTE FOR THE CALLBACK FUNCTIONS!
Reply
#8

What would you need to count the rows for? mysql_insert_id(); returns the id of the row last inserted.
Reply
#9

Quote:
Originally Posted by VincentDunn
View Post
What would you need to count the rows for? mysql_insert_id(); returns the id of the row last inserted.
I need to count the amount of the rows.

I give some condition to select the amount of the rows that fits it. My program need to know this amount.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)