[Plugin] [REL] MySQL Plugin (Now on github!)

Quote:
Originally Posted by ̘ᴄᴛȧᴄ̙
Better to use sscanf 2.0
Nah, mysql_fetch_field_row is better idea.

pawn Код:
public OnPlayerLogin(playerid,password[])
{
    mysql_real_escape_string(password,password);
    mysql_query("SELECT * FROM players WHERE id=%d AND password='%s' LIMIT 1");
    mysql_store_result();
   
    if(mysql_retrieve_row())
    {
        new result[128];
        mysql_fetch_field_row(result,"level"); PlayerInfo[playerid][pLevel] = strval(result);
        mysql_fetch_field_row(result,"admin"); PlayerInfo[playerid][pAdmin] = strval(result);
        //etc
    }
    else
    {
        SendClientMessage(playerid, COLOR_WHITE, " Wrong password.");
    }
   
    mysql_free_result();
    return 1;
}
Reply

$ЂЯĢ, thanks! but when i connect server and use /login command. I have message than password wrong( and in mysqlsql_log.txt i have this error:
Код:
[15:54:26] CMySQLHandler::Query(SELECT * FROM players WHERE id=%d AND password='%s' LIMIT 1) - An error has occured. (Error ID: 1064, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%d AND password='%s' LIMIT 1' at line 1)
This problem with password i am fix. But next problem - account data(level, money, admin level and etc) not loading... (



And what to do with string fields in onplayerlogin?

In the old script, it was this:

Код:
if (rcnt == 93) strmid(PlayerInfo[playerid][pMarriedTo], Field, 0, strlen(Field), 255);
And now I've done on anologii with your script is:

Код:
mysql_fetch_field_row(result,"MarriedTo"); PlayerInfo[playerid][pMarriedTo] = strmid(PlayerInfo[playerid][pMarriedTo], result, 0, strlen(result), 255);
that right?
Reply

Hello, How can I do a wildcard search on a name.
Here is the current query:

SELECT Name,PhoneNumber FROM players WHERE Name=%%%s%%

I think the %% = one % in PAWN and I think again that % = wildcard in MySQL.
So would it be %% %s %% for "(anything)search term(anything)"?
Reply

@PawnNewCommer,

1. Ah what a fail, you need to format query. You can also use that array 'query' instead of 'result' now, so you don't need to open new 128 cells big one.
Код:
new query[128]; mysql_real_escape_string(password,password);
format(query,sizeof(query),"SELECT * FROM players WHERE id=%d AND password='%s' LIMIT 1",PlayerInfo[playerid][pSQLID],password);
mysql_query(query);
...
2. It should be like this:
Код:
mysql_fetch_field_row(PlayerInfo[playerid][pMarriedTo],"MarriedTo");
------------------------
@AlecRae,
I think this would work
Код:
SELECT Name,PhoneNumber FROM players WHERE Name LIKE '%%%s%%'
Reply

Quote:
@AlecRae,
I think this would work
Код:
SELECT Name,PhoneNumber FROM players WHERE Name LIKE '%%%s%%'
Do you think I will still need the %% at each side?
What about:
Код:
SELECT Name,PhoneNumber FROM players WHERE Name LIKE '%s'
Reply

I tried
Код:
SELECT Name,PhoneNumber FROM players WHERE Name LIKE '%%%s%%'
and it works.

Код:
SELECT Name,PhoneNumber FROM players WHERE Name LIKE '%s'
same as
Код:
SELECT Name,PhoneNumber FROM players WHERE Name='%s'
Reply

Quote:
Originally Posted by $ЂЯĢ
I tried
Код:
SELECT Name,PhoneNumber FROM players WHERE Name LIKE '%%%s%%'
and it works.

Код:
SELECT Name,PhoneNumber FROM players WHERE Name LIKE '%s'
same as
Код:
SELECT Name,PhoneNumber FROM players WHERE Name='%s'
Ok thanks, so they are all the same.
One last question: How can I ignore the case of the variable at %s?
Reply

It's case sensitive by default.
Reply

Quote:
Originally Posted by $ЂЯĢ
It's case sensitive by default.
I meant case insensitive though? Will it find "Alec" if I type "ALEC"?

Also:
Код:
format(query, sizeof(query), "SELECT Name,PhoneNumber FROM players WHERE Name LIKE '%%%s%%'", tmp);
mysql_query(query);
mysql_store_result();
new totalResults = mysql_num_rows();
		
if(totalResults == 0)
{
	format(string,sizeof(string),"There was 0 phone numbers found for the name: '%s'.", tmp);
	SendClientMessage(playerid, COLOUR_WHITE, string);
	return 1;
}
		
format(string,sizeof(string),"There was %d phone numbers found for the name: '%s', they are listed below:", totalResults, tmp);
SendClientMessage(playerid, COLOUR_WHITE, string);
		
new ResultName[MAX_PLAYER_NAME], ResultNumber[20];
		
while(mysql_retrieve_row())
{
	mysql_fetch_field_row(ResultName, "Name");
	mysql_fetch_field_row(ResultNumber, "PhoneNumber");
		  
	if(strval(ResultNumber) > 0)
	{
		format(string,sizeof(string),"%s - %d", ResultName, strval(ResultNumber));
		SendClientMessage(playerid, COLOUR_WHITE, string);
	}
}
		
mysql_free_result();
Why does this code say it found 7 numbers but only display 2 of them?

There is no more shown.
Reply

Their 'PhoneNumber' isn't higher than 0 then. That's the only thing which could stop displaying other results.
Reply

You're not meant to put the port in with the IP, you just place the IP, and it connects automatically AFAIK.
Reply

Hello,

Ever since I updated to the new version of the plugin I can't connect to the MySQL server any more.

Код:
[17:54:56] CMySQLHandler::Connect() - Can't connect to MySQL server on 'localhost' (111) (Error ID: 2002)
I pasted the new natives, I renamed the old plugin & uploaded the new one.
I then changed 'localhost' to '127.0.0.1' and I got this error:

Код:
[17:54:56] CMySQLHandler::Connect() - Can't connect to MySQL server on '127.0.0.1' (111) (Error ID: 2003)
I didn't change any setting, so I have no clue wth is wrong. Anyone?
Reply

Is mysql_log.txt reachable by external users?
Reply

Quote:
Originally Posted by cAMo
Is mysql_log.txt reachable by external users?
What do you mean?
Reply

Since the file is stored on my server, could someone navigate to it and download it?

Also: The libmysqlclient.so.15 link is broken. Where can I get a 32-bit Linux file?
Reply

Quote:
Originally Posted by cAMo
Since the file is stored on my server, could someone navigate to it and download it?
If you are stupid enough and you have server files in directory which is accessable from example via HTTP.
Reply

How would you prevent that? When I test my server it automatically writes it to the main dir...
Reply

Quote:
Originally Posted by cAMo
How would you prevent that? When I test my server it automatically writes it to the main dir...
What? If nobody can access your server folder, then nobody will steal your mysql log. If you are still scared you can disable it with mysql_debug(0).
Reply

Is there any reason as to why mysql_reconnect() returns the following: (two attempts)

[22:52:46] >> mysql_reconnect( Connection handle: 0 )
[22:52:46] >> mysql_reconnect() - Invalid connection handle. (You set: 0, Highest connection handle ID is 0).
[22:52:46] >> mysql_reconnect( Connection handle: 1 )
[22:52:46] >> mysql_reconnect() - Invalid connection handle. (You set: 1, Highest connection handle ID is 0).
Reply

What is the most effective way to UPDATE mysql from over 100 PVar's?

How would you structure it?

Reply


Forum Jump:


Users browsing this thread: 15 Guest(s)