[HELP] MySQL Car System
#1

Hello,
I'm making Car System from zero(include).
I have problems:

When i type /createcar, all is good but in mysql_log is : [15:49:48] [WARNING] cache_get_data - no active cache
In phpmyadmin in database make it http://i.imgur.com/6tF5dqX.png
I connect to server, cars dont load it.
When i make /createcar two time in database dont make it but in mysql_log is : [15:53:46] [ERROR] CMySQLQuery::Execute[()] - (error #1062) Duplicate entry '1' for key 'PRIMARY'

COMMAND:
Код:
CMD:createcar(playerid,params[])
{
	new Float:X,Float:Y,Float:Z;
	new carid = GetFreedID();
	if(GetPlayerVehicleID(playerid) == 0)return SendClientMessage(playerid,COLOR_GREY,"Nisi u vozilu!");
	CarInfo[carid][cModel] = GetVehicleModel(GetPlayerVehicleID(playerid));
	GetPlayerPos(playerid,X,Y,Z);
    format(cquery, sizeof(cquery), "INSERT INTO `cars` (cID, cModel, cUlazX, cUlazY, cUlazZ) VALUES ('%d', '%d', '%f', '%f', '%f')", GetFreedID(), CarInfo[carid][cModel], X,Y,Z);
    mysql_function_query(1, cquery, false, "", "");
    CarInfo[carid][cVehicle] = CreateVehicle(CarInfo[carid][cModel],X,Y,Z,0,3,3,-1);
    DestroyVehicle(GetPlayerVehicleID(playerid));
    SendClientMessage(playerid,0xFFFFA8FF,"Auto na prodaju je uspjesno napravljeno!");
	return 1;
}
SAVE/LOAD:
Код:
stock LoadCars()
{
    mysql_tquery(dbHandle, "SELECT * FROM `cars`", "OnCarsLoad", "");
}


stock OnCarsLoad()
{
    new
        rows,
        fields;

    cache_get_data(rows, fields, dbHandle); // CONNECTION

    if( rows )
    {
        new
            i = 0
        ;
        while( rows > i < MAX_CARS )
        {
            CarInfo[i][cID] = cache_get_field_content_int(0, "cID");
            CarInfo[i][cModel] = cache_get_field_content_int(0, "cModel");
            CarInfo[i][cUlazX] = cache_get_field_content_float(0, "cUlazX");
            CarInfo[i][cUlazY] = cache_get_field_content_float(0, "cUlazY");
            CarInfo[i][cUlazZ] = cache_get_field_content_float(0, "cUlazZ");
            CarInfo[i][cVehicle] = CreateVehicle(CarInfo[i][cModel],CarInfo[i][cUlazX],CarInfo[i][cUlazY],CarInfo[i][cUlazZ],0,3,3,-1);
            i++;
        }
    }
}

stock SaveCars()
{
    for(new i = 0; i < MAX_CARS; i++)
    {
		new carid;
		mysql_format(1, cquery, sizeof(cquery), "UPDATE `cars` SET `cID` = '%d', `cModel` = '%d', `cUlazX` = '%f', `cUlazY` = '%f', cUlazZ` = '%f'  WHERE `cID` = '%d' LIMIT 1", CarInfo[carid][cID],CarInfo[carid][cModel],CarInfo[carid][cUlazX],CarInfo[carid][cUlazY],CarInfo[carid][cUlazZ],i);
		mysql_function_query(1, cquery, false, "", "");
	}
}
That is include for SAVE/LOAD.

-----

This is from gamemode on "OnGameModeInit":
LoadCars();
on OnGameModeExit
SaveCars();
And dbHandle is bHandle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_BASE, MYSQL_PASS);(in gamemode)
Reply


Messages In This Thread
[HELP] MySQL Car System - by shulk - 08.09.2013, 13:57
Re: [HELP] MySQL Car System - by shulk - 08.09.2013, 18:05
Re: [HELP] MySQL Car System - by dusk - 08.09.2013, 18:10
Re: [HELP] MySQL Car System - by shulk - 08.09.2013, 20:55
Re: [HELP] MySQL Car System - by shulk - 09.09.2013, 10:22
Re: [HELP] MySQL Car System - by viveka27 - 11.09.2013, 07:20
Re: [HELP] MySQL Car System - by Eyce - 11.09.2013, 08:04

Forum Jump:


Users browsing this thread: 1 Guest(s)