Hi, im making a plugin with the SQLx module and it connects fine.
But, im getting duplicate entries, i made it so it adds 1 entry with the server ip in the plugin_init, but everytime i restart or do a map change a duplicate entry is created in the database.
How do i fix that?
Current Code:
PHP Code:
g_SqlTuple = SQL_MakeDbTuple("secrethost", "root", "secretpass", "mytable");
new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511);
if(SqlConnection == Empty_Handle)
{
set_fail_state(g_Error);
}
new szIP[22], szPort[6];
get_cvar_string("ip", szIP, 15);
get_cvar_string("port", szPort, 5);
format(szIP, 21, "%s:%s", szIP, szPort);
new Handle:Queries[1];
new query[128];
formatex(query, sizeof(query) - 1, "INSERT IGNORE INTO plugin (server_ip) VALUES ('%s')", szIP);
Queries[0] = SQL_PrepareQuery(SqlConnection, query);
for(new Count;Count < 3;Count++)
{
if(!SQL_Execute(Queries[Count]))
{
SQL_QueryError(Queries[Count],g_Error,511);
set_fail_state(g_Error);
}
SQL_FreeHandle(Queries[Count]);
}
SQL_FreeHandle(SqlConnection)
Im using MySQL.
To make it clear: I dont want to insert the IP if the IP already exists in the DB.
__________________