MySQL simple information retrieving [Help]
#1

Hello, i'm new to the MySQL system in SA-MP, and since it's not very similar to PHP's MySQL, I have some syntax issues.

What I basicly want to do is take information from my MySQL database and print them out in PAWNO.

Here's my database:



Above OnGameModeInit:
Quote:

forward sqlConnection();
public sqlConnection() {
return mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS);
}

OnGameModeInit:
Quote:

new connection = sqlConnection();
printf("CONNECTION: '%i'", connection);
new Cache:result = mysql_query(connection, "SELECT username FROM player");
new playerName[MAX_PLAYER_NAME];

cache_get_value_name(0, "username", playerName, sizeof(playerName));
printf("PLAYER_NAME: '%s'", playerName);

I've tried different variations of cache_get_value and i've also tried to do it with & without sizeof().


Console prints:
Reply
#2

I haven't tried before this. Here is command version:

Код:
new Cache:result = mysql_query(connection, "SELECT username FROM player");
if(cache_num_rows())
{
	new PlayerName[24];
	for(new i = 0; i != cache_num_rows(); i++)
	{
	    cache_get_value_name(i, "username", PlayerName, sizeof(PlayerName));
	    printf("PLAYER_NAME: '%s'", PlayerName);
	}
}
cache_delete(result);
Reply
#3

That didnt do / print out anything :/

The issue is that the cache is empty.
Reply
#4

It is weird how your connection handle is 1 when you have wrong parameters in mysql_connect for R40+

https://sampwiki.blast.hk/wiki/MySQL/R40#mysql_connect

3rd is password and 4th is database, you have them the other way around. Anyway, still check mysql logs.
Reply
#5

Thanks for showing me the mysql_connect, it still returns 1 and mysql_log(ALL) doesn't do anything.

And my cache is still empty :/
Reply
#6

Bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)