Need help with MySQL
#1

Ok so basically i set up a MOTD system using Blue G's MySQL R7 plugin and everything seems to be fine the server starts no errors in the debug.So i created the table "misc" with phpMyAdmin and inserted the columns which are 5 columns VARCHAR type 129 characters lenght.The problem is it doesn't write the data in the table...can someone help out:

pawn Код:
stock SaveMOTD()
{
    new query[1024];

    format(query, sizeof(query), "UPDATE `misc` SET ");
   
    format(query, sizeof(query), "%s `sapdMOTD` = '%s',", query, g_mysql_ReturnEscaped(SAPDMOTD, MainPipeline));
    format(query, sizeof(query), "%s `govMOTD` = '%s',", query, g_mysql_ReturnEscaped(GOVMOTD, MainPipeline));
    format(query, sizeof(query), "%s `haMOTD` = '%s',", query, g_mysql_ReturnEscaped(HAMOTD, MainPipeline));
    format(query, sizeof(query), "%s `adminMOTD` = '%s',", query, g_mysql_ReturnEscaped(AdminMOTD, MainPipeline));
    format(query, sizeof(query), "%s `loginMOTD` = '%s'", query, g_mysql_ReturnEscaped(LoginMOTD, MainPipeline));

    mysql_function_query(MainPipeline, query, false, "OnQueryFinish", "i", SENDDATA_THREAD);
}

stock mysql_Init()
{
    new SQL_HOST[64], SQL_DB[64], SQL_USER[32], SQL_PASS[128], iValue;
    new fileString[128], File: fileHandle = fopen("mysql.cfg", io_read);

    while(fread(fileHandle, fileString, sizeof(fileString))) {
        if(ini_GetValue(fileString, "HOST", SQL_HOST, sizeof(SQL_HOST))) continue;
        if(ini_GetValue(fileString, "DB", SQL_DB, sizeof(SQL_DB))) continue;
        if(ini_GetValue(fileString, "USER", SQL_USER, sizeof(SQL_USER))) continue;
        if(ini_GetValue(fileString, "PASS", SQL_PASS, sizeof(SQL_PASS))) continue;
        if(ini_GetInt(fileString, "SERVER", servernumber)) continue;
        if(ini_GetInt(fileString, "DEBUG", iValue)) continue;
    }
    fclose(fileHandle);

    mysql_debug(iValue);
    MainPipeline = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
    setproperty(.name = "pipeline", .value = MainPipeline);

    printf("[MySQL] (Main Pipelines) Connecting to %s...", SQL_HOST);

    if(mysql_ping(MainPipeline) == -1)
    {
        printf("[MySQL] (MainPipeline) Fatal Error! Could not connect to MySQL: Host %s - DB: %s - User: %s", SQL_HOST, SQL_DB, SQL_USER);
        print("[MySQL] Note: Make sure that you have provided the correct connection credentials.");
        SendRconCommand("exit");
    }
    else
    {
        print("[MySQL] (MainPipeline) Connection successful toward MySQL Database Server!");
    }
    return 1;
}

stock LoadMOTD()
{
    mysql_function_query(MainPipeline, "SELECT `sapdMOTD`,`govMOTD`,`haMOTD`,`adminMOTD`,`loginMOTD` FROM `misc`", true, "OnQueryFinish", "iii", LOADMOTDDATA_THREAD, INVALID_PLAYER_ID, -1);
}

forward OnQueryFinish(resultid, extraid, handleid);
public OnQueryFinish(resultid, extraid, handleid)
{
    new rows, fields;
    if(resultid != SENDDATA_THREAD) {
        if(extraid != INVALID_PLAYER_ID) {
            if(g_arrQueryHandle{extraid} != -1 && g_arrQueryHandle{extraid} != handleid) return 0;
        }
        cache_get_data(rows, fields, MainPipeline);
    }
    switch(resultid)
    {
        case LOADMOTDDATA_THREAD:
        {
            for(new i;i < rows;i++)
            {
                cache_get_field_content(i, "sMOTD", ServerMOTD, MainPipeline);
                cache_get_field_content(i, "sapdMOTD", SAPDMOTD, MainPipeline);
                cache_get_field_content(i, "govMOTD", GOVMOTD, MainPipeline);
                cache_get_field_content(i, "haMOTD", HAMOTD, MainPipeline);
                cache_get_field_content(i, "adminMOTD", AdminMOTD, MainPipeline);
                cache_get_field_content(i, "loginMOTD", LoginMOTD, MainPipeline);
                break;
            }
        }
    }
    return 1;
}
And the mysql_log outputs:

pawn Код:
[04:43:05]  
[04:43:05]  ** MySQL Debugging enabled (11/18/12)
[04:43:05]  
[04:43:05] >> mysql_connect(5.39.11.60, 6314_mikey, 6314_mikey, ******) on port 3306
[04:43:05] CMySQLHandler::CMySQLHandler() - constructor called.
[04:43:05] CMySQLHandler::CMySQLHandler() - Connecting to "5.39.11.60" | DB: "6314_mikey" | Username: "6314_mikey"
[04:43:05] CMySQLHandler::Connect() - Connection was successful.
[04:43:05] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.
[04:43:05] >> mysql_ping( Connection handle: 1 )
[04:43:05] CMySQLHandler::Ping() - Connection is still alive.
[04:43:05] >> mysql_query_callback( Connection handle: 1 )
[04:43:05] Passing query SELECT `sapdMOTD`,`govMOTD`,`haMOTD`,`adminMOTD`,`loginMOTD` FROM `misc` | iii
[04:43:05] ProcessQueryThread(OnQueryFinish) - Query was successful. (SELECT `sapdMOTD`,`govMOTD`,`haMOTD`,`adminMOTD`,`loginMOTD` FROM `misc`)
[04:43:05] ProcessQueryThread(OnQueryFinish) - Data caching enabled.
[04:43:05] CMySQLHandler::StoreResult() - Result was stored.
[04:43:05] CMySQLHandler::FreeResult() - Result was successfully free'd.
[04:43:05] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[04:43:05] OnQueryFinish(iii) - Threaded function called.
[04:43:05] >> cache_get_data( Connection handle: 1 )
[04:43:05] ProcessTick() - The cache has been cleared.
Thanks for the help in advance.
Reply
#2

For the sole purpose of saving five strings, a simple flat file would be better, in my opinion. As for the problem: the table must not be empty if you want the update statement to work.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
For the sole purpose of saving five strings, a simple flat file would be better, in my opinion. As for the problem: the table must not be empty if you want the update statement to work.
Oh well yeah i think the same as you but the owner wants to integrate those MOTDs with our homepage -.-
Nevermind that thanks for your help i'll use the INSERT statement once so it can set some values.
Reply
#4

Sorry for reposting but i suck at MySQL lol....can someone tell me which MySQL function can i use to write data in the table columns for the first time?
Reply
#5

Insert ..
Ex:
INSERT INTO tblname VALUES (v1,v2,v3,etc) ..
Or if you want to specify the columns name
INSERT INTO tblname (cl1,cl2,etc) VALUES (v1,v2,etc)
Reply
#6

thanks so much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)