←  Problemy

AMXX.pl: Support AMX Mod X i SourceMod

»

Pobieranie danych z MySQL przez moduł SQLX

Locked

  • +
  • -
Huntersor's Photo Huntersor 28.08.2011

Witam.
Mam problem przy pobieraniu danych z bazy MySQL

public mysql_result(command[],field){
    new error[128], errno;
    new result[2];
    
    new Handle:sqlT;
    new Handle:query;
    new Handle:SQL
    
    sqlT = SQL_MakeDbTuple("localhost","root","","db_mod");
    SQL =  SQL_Connect(sqlT, errno, error, 127);
    
    if (SQL == Empty_Handle){
        server_print("[TibiaMOD] MySQL Connect failed - error code: %i", error);
    }
    
    query = SQL_PrepareQuery(SQL,command);
    
    if(!SQL_Execute(query)){
        SQL_QueryError(query, error, 127)
        server_print("[TibiaMOD] Error from mysql_result - error code %i", error);
    }else{
        SQL_ReadResult(query, field, result,255);
        server_print("Dane: %s",result[0]);
    }
 
    SQL_FreeHandle(sqlT);
    SQL_FreeHandle(query);
    SQL_FreeHandle(SQL);
    
    return result[0];
}
Ten kod pobiera z sql wybrane dane np
ostatnie_twoje_ip = mysql_result("SELECT * FROM users WHERE player='nazwa gracza' ",2);
no i ten kod zwraca mi ip z jakiego korzystał gracz ostatnio (w tabeli to polema atrybuty varchar(255) ) no i jak pobieram to i wyświetlam to jest poprawnie,
ale jak chce pobrać jakieś liczby z pola o typie int i umieścić np w player_exp[id] to zapisują się tak jakieś cyferki różniące się od wpisu w rekordzie?
W player_exp[id] zapisuje się doświadczenie zdobyte przez gracza.
Wie może ktoś jak to naprawić ?
Quote

  • +
  • -
Hiroshima's Photo Hiroshima 28.08.2011

Automatyczna wiadomość


Ten temat został przeniesiony z forum:
AMX Mod XProblemy
do
Scripting AMXXProblemy

Quote

  • +
  • -
DarkGL's Photo DarkGL 28.08.2011

liczbe float / int i string odczytuje sie inaczej
Retrieves the current result.
A successful query starts at the first result, so you should not call SQL_NextRow() first.
Passing no extra params - return int
Passing one extra param - return float in 1st extra arg
Passing two extra params - return string in 1st arg, max length in 2nd

Example:
new num = SQL_ReadResult(query, 0)
new Float:num2
new str[32]
SQL_ReadResult(query, 1, num2)
SQL_ReadResult(query, 2, str, 31)
Quote

  • +
  • -
Huntersor's Photo Huntersor 28.08.2011

Dzięki faktycznie jest to w dokumentacji nie zauważyłem tego ;]
Quote

Adminek AMXX.PL's Photo Adminek AMXX.PL 28.08.2011

Wiadomość wygenerowana automatycznie


Ten temat został zamknięty przez moderatora.

Powód: wyjaśnione

Jeśli się z tym nie zgadzasz, Dołączona grafika raportuj ten post, a moderator lub administrator rozpatrzy go ponownie.


Z pozdrowieniami,
Zespół AMXX.PL
Quote
Locked