Member
Join Date: Apr 2011
Location: Estonia
|
09-22-2011
, 13:30
Sqlx Help
|
#1
|
Hi!
I Need help with sqlx. If someone could fix this, i would be quite thankful.
Error:
PHP Code:
L 09/20/2011 - 17:30:07: [MySQL] Invalid handle: 0 L 09/20/2011 - 17:30:07: [AMXX] Run time error 10 (plugin "dr.amxx") (native "SQL_FreeHandle") - debug not enabled! L 09/20/2011 - 17:30:07: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
Code:
PHP Code:
public MySql_Init() { g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db); // ok, we're ready to connect new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error)); if(SqlConnection == Empty_Handle) { // stop the plugin with an error message set_fail_state(g_Error); } new Handle:Queries; // we must now prepare some random queries Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS deathrun (nick varchar(255),ip varchar(255),steamid varchar(32),elud int(11))");
if(!SQL_Execute(Queries)) { // if there were any problems the plugin will set itself to bad load. SQL_QueryError(Queries,g_Error,charsmax(g_Error)); set_fail_state(g_Error); } // Free the querie SQL_FreeHandle(Queries); // you free everything with SQL_FreeHandle SQL_FreeHandle(SqlConnection) ; }
public plugin_end() { // free the tuple - note that this does not close the connection, // since it wasn't connected in the first place SQL_FreeHandle(g_SqlTuple); }
public Load_MySql(id) { new szPlayerName[32]; get_user_name(id, szPlayerName, charsmax(szPlayerName)); new szSteamId[32]; get_user_authid(id, szSteamId, charsmax(szSteamId)); new szIp[32]; get_user_ip(id, szIp, charsmax(szIp)); new Data[1] Data[0] = id //we will now select from the table `tutorial` where the steamid match format(szTemp,charsmax(szTemp),"SELECT * FROM `tutorial` WHERE (`tutorial`.`steamid` = '%s')", szSteamId) SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1) } public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) { if(FailState == TQUERY_CONNECT_FAILED) { log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error); } else if(FailState == TQUERY_QUERY_FAILED) { log_amx("Load Query failed. [%d] %s", Errcode, Error); }
new id; id = Data[0]; if(SQL_NumResults(Query) < 1) { //.if there are no results found new szIp[32]; get_user_ip(id, szIp, charsmax(szIp)); new szPlayerName[32]; get_user_name(id, szPlayerName, charsmax(szPlayerName)); new szSteamId[32]; get_user_authid(id, szSteamId, charsmax(szSteamId)); // get user's steamid // if its still pending we can't do anything with it if (equal(szSteamId,"ID_PENDING")) return PLUGIN_HANDLED; new szTemp[512]; // now we will insturt the values into our table. format(szTemp,charsmax(szTemp),"INSERT INTO `deathrun` (`nick` , `ip`, `steamid`, `elud`)VALUES ('%s','%s','%s','0');",szIp,szPlayerName,szSteamId); SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp); } else { // if there are results found g_Lifes[id] = SQL_ReadResult(Query, 1); } return PLUGIN_HANDLED; }
public Save_MySql(id) { new iPlayers[ 32 ], iNum, iPlayer; iPlayer = iPlayers[ id ]; get_players( iPlayers, iNum, "c" ); new szIp[32]; get_user_ip(id, szIp, charsmax(szIp)); new szPlayerName[32]; get_user_name(id, szPlayerName, charsmax(szPlayerName)); new szSteamId[32], szTemp[512]; get_user_authid(id, szSteamId, charsmax(szSteamId)); // get user's steamid // Here we will update the user hes information in the database where the steamid matches. format(szTemp,charsmax(szTemp),"UPDATE `deathrun` set `elud`= `elud` + '%s' WHERE `deathrun`.`steamid` = %s OR `deathrun`.`nick` = %s OR `deathrun`.`ip` = %s ;",g_Lifes[ iPlayer ],szSteamId,szPlayerName,szIp); SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp); }
public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) { SQL_FreeHandle(Query); return PLUGIN_HANDLED; }
Last edited by rainin; 09-23-2011 at 08:19.
|
|