Do not save data mysql.
#1

I made this system:

pawn Код:
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <macros>
#include <colores>

new ConexionDB;

public OnFilterScriptInit()
{
    CargarPosicionLenador();
    return 1;
}

enum PosLenador
{
    Float:X,
    Float:Y,
    Float:Z,
    World,
    Interior,
    Float:Angle,
    PickupID,
};
new PosicionLenador[PosLenador];

funcion CargarPosicionLenador()
{
    new Query[200];
    format(Query, sizeof(Query), "SELECT * FROM `posicionlenador`");
    mysql_function_query(ConexionDB, Query, true, "CargarPosicionLenador2", "i",3);
    print("CargarPosicionLenador");
}

funcion CargarPosicionLenador2(resultid, extraid, ConnectionHandle)
{
    new Rows, Field;
    if(resultid != 0)
    {
        cache_get_data(Rows, Field);
    }
    switch(resultid)
    {
        case 3:
        {
            new content[32];
            cache_get_field_content(0, "PosicionX",     content); PosicionLenador[X]        = floatstr(content);
            cache_get_field_content(0, "PosicionY",     content); PosicionLenador[Y]        = floatstr(content);
            cache_get_field_content(0, "PosicionZ",     content); PosicionLenador[Z]        = floatstr(content);
            cache_get_field_content(0, "Mundo",         content); PosicionLenador[World]    = strval(content);
            cache_get_field_content(0, "Interior",      content); PosicionLenador[Interior] = strval(content);
            cache_get_field_content(0, "Angulo",        content); PosicionLenador[Angle]    = floatstr(content);
            cache_get_field_content(0, "Pickup",        content); PosicionLenador[PickupID] = strval(content);
        }
    }
    return 1;
}

CMD:cambiarpos(playerid, params[])
{
    CargarPosicionLenador();
    return 1;
}
CMD:cambiarpos2(playerid, params[])
{
    new query[200];
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid, x, y, z);
    new Float:angle;
    GetPlayerFacingAngle(playerid, angle);
    PosicionLenador[X] = x;
    PosicionLenador[Y] = y;
    PosicionLenador[Z] = z;
    PosicionLenador[World] = GetPlayerVirtualWorld(playerid);
    PosicionLenador[Interior] = GetPlayerInterior(playerid);
    PosicionLenador[Angle] = angle;
//  MoveStreamPickup(PosicionLenador[PickupID],PosicionLenador[X],PosicionLenador[Y],PosicionLenador[Z]);
    SendClientMessage(playerid, ColorInfoAdmins, "[!] Cambiaste la posiciуn del trabajo de leсador a tu posiciуn");
    format(query, 900, "UPDATE `posicionlenador ` SET `PosicionX`='%f',`PosicionY`='%f',`PosicionZ`='%f',`Mundo`='%d',`Interior`='%d',`Angulo`='%f',`Pickup`='%d'");
    mysql_function_query(ConexionDB, query, true, "OnQueryFinish", "ii", 0, playerid);
    mysql_query(1, query);
    return 1;
}
Data DB:

Код:
--
-- Estructura de tabla para la tabla `posicionlenador`
--

CREATE TABLE IF NOT EXISTS `posicionlenador` (
  `PosicionX` float NOT NULL,
  `PosicionY` float NOT NULL,
  `PosicionZ` float NOT NULL,
  `Mundo` int(2) NOT NULL,
  `Interior` int(2) NOT NULL,
  `Angulo` float NOT NULL,
  `Pickup` int(4) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
By using the command does not update the db.

ї Where is the error ?.
Reply
#2

Does it say anything in your rcon console or mysql logs?
Reply
#3

format(query, 900, "UPDATE `posicionlenador ` SET `PosicionX`='%f',`PosicionY`='%f',`PosicionZ`='%f' ,`Mundo`='%d',`Interior`='%d',`Angulo`='%f',`Picku p`='%d'");

`posicionlenador ` <-- space, table "posicionlenador " not exist

I recommend not to use such record

recommend:
Код:
"UPDATE posicionlenador SET PosicionX='%f', PosicionY='%f', PosicionZ='%f', Mundo='%d', Interior='%d', Angulo='%f', Pickup='%d'"
Reply
#4

After looking at the piece of code I realized that you didn't set the values in the query. (Unless you deleted it before posting)..
Reply
#5

No errors in the console.

I added this:

pawn Код:
public OnFilterScriptInit()
{
    CargarPosicionLenador();
    mysql_log(LOG_ALL);
    ConexionDB = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
    if(mysql_errno() != 0)
    {
        printf("[MySQL] La conexiуn no se ha podido realizar.");
        SendRconCommand("exit"); // cerramos el servidor para evitar problemas
    }
    else
    {
        printf("");
        printf("");
        printf("");
        printf("");
        printf("");
        printf("[MySQL] La conexiуn se ha realizado correctamente.");
    }
    return 1;
}
But not save data...

Help please.
Reply
#6

read my reply, it might solve your problem!
Reply
#7

ї This ?

Код:
#define 	MYSQL_HOST        "IP"
#define    	MYSQL_USER        "User"
#define    	MYSQL_PASSWORD    "PassDB" 
#define    	MYSQL_DATABASE    "DB"
EDIT:

mysql.log

Код:
[22:12:41] [DEBUG] mysql_connect - host: "localhost", user: "root", database: "db_trebol2015", password: "****", port: 3306, autoreconnect: true
[22:12:41] [DEBUG] CMySQLHandle::Create - creating new connection..
[22:12:41] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[22:12:41] [DEBUG] CMySQLHandle::Create - connection created with ID = 1
[22:12:41] [DEBUG] CMySQLConnection::Connect - connection was successful
[22:12:41] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[22:12:41] [DEBUG] CMySQLConnection::Connect - connection was successful
[22:12:41] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[22:12:41] [DEBUG] mysql_errno - connection: 1
[22:12:41] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM `posicionlenador`", callback: "CargarPosicionLenador2", format: "i"
[22:12:41] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[22:12:41] [DEBUG] mysql_tquery - scheduling query "SELECT * FROM `posicionlenador`"..
[22:12:41] [DEBUG] CMySQLQuery::Execute[CargarPosicionLenador2(i)] - starting query execution
[22:12:41] [DEBUG] CMySQLQuery::Execute[CargarPosicionLenador2(i)] - query was successful
[22:12:42] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[22:12:42] [DEBUG] CMySQLQuery::Execute[CargarPosicionLenador2(i)] - data being passed to ProcessCallbacks()
[22:12:43] [DEBUG] Calling callback "CargarPosicionLenador2"..
[22:12:43] [DEBUG] cache_get_data - connection: 1
[22:12:43] [DEBUG] cache_get_field_content - row: 0, field_name: "PosicionX", connection: 1, max_len: 32
[22:12:43] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('0')
[22:12:43] [DEBUG] cache_get_field_content - row: 0, field_name: "PosicionY", connection: 1, max_len: 32
[22:12:43] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('0')
[22:12:43] [DEBUG] cache_get_field_content - row: 0, field_name: "PosicionZ", connection: 1, max_len: 32
[22:12:43] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('0')
[22:12:43] [DEBUG] cache_get_field_content - row: 0, field_name: "Mundo", connection: 1, max_len: 32
[22:12:43] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('0')
[22:12:43] [DEBUG] cache_get_field_content - row: 0, field_name: "Interior", connection: 1, max_len: 32
[22:12:43] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('0')
[22:12:43] [DEBUG] cache_get_field_content - row: 0, field_name: "Angulo", connection: 1, max_len: 32
[22:12:43] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('0')
[22:12:43] [DEBUG] cache_get_field_content - row: 0, field_name: "Pickup", connection: 1, max_len: 32
[22:12:43] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('0')
[22:12:43] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[22:12:43] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called
Reply
#8

Help please.
Reply
#9

Solved by a user of section Spanish.

Thank you Tirael.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)