MySQL simple information retrieving [Help] - 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: MySQL simple information retrieving [Help] (
/showthread.php?tid=636606)
MySQL simple information retrieving [Help] -
OriginalShark - 30.06.2017
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:
Re: MySQL simple information retrieving [Help] -
Freedom. - 30.06.2017
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);
Re: MySQL simple information retrieving [Help] -
OriginalShark - 30.06.2017
That didnt do / print out anything :/
The issue is that the cache is empty.
Re: MySQL simple information retrieving [Help] -
Konstantinos - 01.07.2017
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.
Re: MySQL simple information retrieving [Help] -
OriginalShark - 01.07.2017
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 :/
Re: MySQL simple information retrieving [Help] -
OriginalShark - 02.07.2017
Bump