Posts: 133
Threads: 4
Joined: Mar 2009
Quote:
Originally Posted by JustBored
Im having an issue with the GDK, i've been trying to use the mysql_connect function from the BlueG plugin but everytime i call the function the samp-server crashes: this is my code
When i declare the function:
pawn Код:
namespace Hooks { class MySQLHooks { public: static cell mysql_connect(char *host, char *user, char* db, char *pass); //more functions }; cell MySQLHooks::mysql_connect(char *host, char *user, char* db, char *pass) { return (cell)sampgdk_InvokeNative(sampgdk_FindNative("mysql_connect"), "ssss", host, user, db, pass); } //more functions };
And the part where i use the function:
pawn Код:
struct connectiondata { char *host = "localhost"; char *db = "tdm"; char *password = ""; char *user = "root"; cell ConnectionHandle = 0; }; connectiondata *ConnectionData;
PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit() { logprintf("Inited"); ConnectionData->ConnectionHandle = Hooks::MySQLHooks::mysql_connect(ConnectionData->host, ConnectionData->user, ConnectionData->db, ConnectionData->password); //this is the line where the plugin crashes if (Hooks::MySQLHooks::mysql_ping(ConnectionData->ConnectionHandle)) { logprintf("The MySQL system inited correctly: (HOST: %s | User: %s | DB: %s | Password: %s", ConnectionData->host, ConnectionData->user, ConnectionData->db, ConnectionData->password); } else { logprintf("I coudnt connect to the MySQL system."); } return true; }
|
Because you are using a wrong format with sampgdk_InvokeNative.
String is not like other one cell length types. If you use a string you MUST mention the length of string in format string.
You can do this like "S[FIXED_LENGTH]" or "[S[*num_argument_that_contains_sizeof_string]".
So try to use "S[1024]S[1024]S[1024]S[1024]".