Getting MySQL INSERT ID MySQL R7 plugin
#1

Helllo, I have another problem I can't solve.

If I insert query then How I get the ID of the INSERTED query?

The Code:
PHP Code:
if(EDIT_OBJ_ID[playerid]) {
            
SetDynamicObjectPos(EDIT_OBJ_ID[playerid], xyz);
            
SetDynamicObjectRot(EDIT_OBJ_ID[playerid], rxryrz);
            
EDIT_OBJ_ID[playerid] = objectid;
                
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][0] = x;
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][1] = y;
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][2] = z;
            
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][0] = rx;
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][1] = ry;
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][2] = rz;
            
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureHouseID] = getPlayerHouseID(playerid);
            
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureINT] = GetPlayerInterior(playerid);
            
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureVW] = GetPlayerVirtualWorld(playerid);
            
            if(
isnull(furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePlanter])) {        
                
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePlanter] = playerVariables[playerid][pNormalName];
                
format(szQueryInputsizeof(szQueryInput), "INSERT INTO furniture (objectModelID, objectPosX, objectPosY, objectPosZ, objectHouseID, objectRotX, objectRotY, objectRotZ, objectPlanterName, objectVW, objectINT) VALUES ('%d', '%f', '%f', '%f', '%d', '%f', '%f', '%f', '%s', '%d', '%d')"furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureOID],
                
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][0], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][1], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePos][2], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureHouseID],
                
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][0], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][1], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureRot][2], furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePlanter],furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureINT],furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureVW]);
                
mysql_function_query(connectionszQueryInputtrue"insertFurniture""d"playerid);
                
#if defined DEBUG
                    
printf("%s"szQueryInput);
                
#endif
                
EDIT_OBJ_ID[playerid] = 0;
                
pEDIT_OBJ[playerid] = 0;
            } else if(!
isnull(furnitureVariables[EDIT_OBJ_ID[playerid]][fFurniturePlanter])) {            
                
saveFurniture(EDIT_OBJ_ID[playerid]);
                
EDIT_OBJ_ID[playerid] = 0;
                
pEDIT_OBJ[playerid] = 0;
            }
        } 
The public function
PHP Code:
public insertFurniture(playerid) {
    
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureID] = mysql_insert_id();
    return 
1;

And saveFunriture stck:
PHP Code:
public saveFurniture(furnitureID) {
    
format(szQueryInputsizeof(szQueryInput), "UPDATE furniture SET objectModelID = '%d', objectPosX = '%f', objectPosY = '%f', objectPosZ = '%f', objectHouseID = '%d', objectRotX = '%f', objectRotY = '%f', objectRotZ = '%f', objectPlanterName = '%s', objectVW = '%d', objectINT = '%d'",
    
furnitureVariables[furnitureID][fFurnitureOID], furnitureVariables[furnitureID][fFurniturePos][0], furnitureVariables[furnitureID][fFurniturePos][1], furnitureVariables[furnitureID][fFurniturePos][2], furnitureVariables[furnitureID][fFurnitureHouseID], furnitureVariables[furnitureID][fFurnitureRot][0], furnitureVariables[furnitureID][fFurnitureRot][1], furnitureVariables[furnitureID][fFurnitureRot][2], furnitureVariables[furnitureID][fFurniturePlanter],
    
furnitureVariables[furnitureID][fFurnitureVW], furnitureVariables[furnitureID][fFurnitureINT]);
    
    
format(szQueryInputsizeof(szQueryInput), "%s WHRE objectID = '%d'"szQueryInputfurnitureVariables[furnitureID][fFurnitureID]);
    
#if defined DEBUG
        
printf("%s"szQueryInput);
    
#endif
    
return 1;

Thanks.
Reply
#2

Just change

pawn Code:
mysql_function_query(connection, szQueryInput, true, "insertFurniture", "d", playerid);
to

pawn Code:
mysql_function_query(connection, szQueryInput, false, "insertFurniture", "d", playerid);
Reply
#3

Whenever you use INSERT INTO or UPDATE is not necessary to use cache parameter to true. If I remember correct, it ignores it and it set it to true (always) in the newest versions.

Anyways, what you're looking for is:
pawn Code:
mysql_insert_id( )
Like you have in a callback. That should work.

Quote:
pawn Code:
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureID] = mysql_insert_id();
Reply
#4

Quote:
Originally Posted by _Zeus
View Post
Whenever you use INSERT INTO or UPDATE is not necessary to use cache parameter to true. If I remember correct, it ignores it and it set it to true (always) in the newest versions.

Anyways, what you're looking for is:
pawn Code:
mysql_insert_id( )
Like you have in a callback. That should work.
Yes, but I give this value to the variable:

PHP Code:
public insertFurniture(playerid) {
    
furnitureVariables[EDIT_OBJ_ID[playerid]][fFurnitureID] = mysql_insert_id();
    return 
1;

But if I use it, it gives me 0.

EDIT::: Thank You both..
My stupid mistake. I made EDIT_OBJ_ID[playerid] = 0 before INSERT. That's Why it gave me 0.

Thanks. REP+.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)