Getting string from SQL
#7

Quote:
Originally Posted by AmigaBlizzard
Посмотреть сообщение
Try:

pawn Код:
cache_get_field_content(51, "NickName", AccInfo[playerid][NickName], connectionhandle, 64);
It will load the data and put it inside your array at the same time.
https://sampwiki.blast.hk/wiki/MySQL/R33..._field_content
Still doesnt help out, it still displays the string as NULL in game

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Here's an example:
pawn Код:
// ** INCLUDES

#include <a_samp>
#include <a_mysql>

// ** DEFINES

// *** DATABASE

#define MYSQL_HOST "localhost"
#define MYSQL_USER "root"
#define MYSQL_PASSWORD ""
#define MYSQL_DATABASE "mysql_get_string"

// *** VEHICLES DATABASE

// **** TABLES

#define TABLE_STRINGS "strings"

// **** FIELDS

#define STRINGS_TEXT "text"

// ** VARIABLES

// *** GLOBAL VARIABLES

// **** DATABASE

static strings_database;

// ** MAIN

main()
{
    print("Loaded \"mysql_get_string.amx\".");
}

// ** CALLBACKS

public OnGameModeInit()
{
    LoadDatabase();
    FindString("test");
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// ** FUNCTIONS

stock LoadDatabase()
{
    mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
    strings_database = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);

    if(mysql_errno(strings_database) != 0)
    {
        printf("[MySQL] Couldn't connect to %s.", MYSQL_DATABASE);
    }
    else
    {
        printf("[MySQL] Connected to %s.", MYSQL_DATABASE);

        new query[300], string[144];
        format(string, sizeof(string), "CREATE TABLE IF NOT EXISTS %s(", TABLE_STRINGS);
        strcat(query, string);

        format(string, sizeof(string), "%s VARCHAR(128))", STRINGS_TEXT);
        strcat(query, string);

        mysql_query(strings_database, query);
    }  
    return 1;
}

stock FindString(string[])
{
    new query[500];
    format(query, sizeof(query), "SELECT `%s` FROM `%s`", STRINGS_TEXT, TABLE_STRINGS);
    mysql_function_query(strings_database, query, true, "OnStringsQuery", "s", string);
    return 1;
}

forward OnStringsQuery(string[]);
public OnStringsQuery(string[])
{
    new result[128], bool:found = false;
    for(new i = 0, j = cache_get_row_count(strings_database); i < j; i ++)
    {
        cache_get_field_content(i, STRINGS_TEXT, result, strings_database, sizeof(result));

        if(!strcmp(result, string, false))
        {
            found = true;
            break;
        }
    }

    if(found)
    {
        printf("The string \"%s\" was found in the database!", string);
    }
    else
    {
        printf("The string \"%s\" wasn't found in the database.", string);
    }
    return 1;
}
But of course on your script, you would want to know the row ID to handle ("i" on my example) for better performance.
Ill try to do something like this but Im using Tquerries
Reply


Messages In This Thread
Getting string from SQL - by TwinkiDaBoss - 09.12.2015, 18:24
Re: Getting string from SQL - by Vince - 09.12.2015, 18:47
Re: Getting string from SQL - by TwinkiDaBoss - 09.12.2015, 18:52
Re: Getting string from SQL - by TwinkiDaBoss - 09.12.2015, 20:37
Re: Getting string from SQL - by AmigaBlizzard - 09.12.2015, 20:57
Re: Getting string from SQL - by SickAttack - 09.12.2015, 21:07
Re: Getting string from SQL - by TwinkiDaBoss - 10.12.2015, 16:16
Re: Getting string from SQL - by TwinkiDaBoss - 10.12.2015, 23:17
Re: Getting string from SQL - by arakuta - 10.12.2015, 23:32
Re: Getting string from SQL - by TwinkiDaBoss - 10.12.2015, 23:36

Forum Jump:


Users browsing this thread: 5 Guest(s)