| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include <YSI_Coding\y_hooks>
- static MySQL:s_MySQLHandle;
- forward OnMySQLConnected();
- forward OnMySQLPreClose();
- #if defined LOCALHOST
- #define MYSQL_HOST "localhost"
- #define MYSQL_USER "root"
- #define MYSQL_PASS ""
- #define MYSQL_DATA "gtastories"
- #else
- #define MYSQL_HOST "217.146.86.250"
- #define MYSQL_USER "db54987"
- #define MYSQL_PASS "EWH8vTI3cg"
- #define MYSQL_DATA "db54987"
- #endif
- hook OnGameModeInit()
- {
- print("MySQL database setting up...");
- new MySQLOpt: optionid = mysql_init_options();
- mysql_set_option(optionid, AUTO_RECONNECT, true);
- s_MySQLHandle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATA);
- if(s_MySQLHandle == MYSQL_INVALID_HANDLE || mysql_errno(s_MySQLHandle) != 0) print("MySQL failed to connect. Server shutting down...");
- else CallRemoteFunction("OnMySQLConnected", "");
- return 1;
- }
- hook OnGameModeExit()
- {
- print("Pre-Closing the database...");
- CallRemoteFunction("OnMySQLPreClose", "");
- mysql_close(s_MySQLHandle);
- return 1;
- }
- public OnMySQLConnected()
- {
- print("MySQL connection is successful.");
- return 1;
- }
- public OnMySQLPreClose()
- {
- print("MySQL connection has been closed.");
- return 1;
- }
- public OnQueryError(errorid, const error[], const callback[], const query[], MySQL:handle)
- {
- switch(errorid)
- {
- case 1136: printf("[MySQL] Error 1136 | Column count does not match value count => \"%s\"", query);
- case 1054: printf("[MySQL] Error 1054 | Invalid field name => \"%s\"", query);
- case 1065: printf("[MySQL] Error 1065 | Query was empty (variable's size too small?) => \"%s\" from \"%s\"", query, callback);
- case 1058: printf("[MySQL] Error 1058 | Column count doesn't match value count => \"%s\" from \"%s\"", query, callback);
- case 1203: printf("[MySQL] Error 1203 | User already has more than 'max_user_connections' active connections => \"%s\" from \"%s\"", query, callback);
- case 1045: printf("[MySQL] Error 1045 | Access denied");
- case ER_SYNTAX_ERROR: printf("[MySQL] Syntax Error => \"%s\"", query);
- default: printf("[MySQL] Error %d | Callback: %s | \"%s\"", errorid, callback, query);
- }
- return 1;
- }
- stock MySQL:MySQL_GetHandle()
- {
- return s_MySQLHandle;
- }
|