mysql_insert_id return 0 -
CoaPsyFactor - 05.06.2012
Hi there,
So I have this little problem, when script do some query, with INSERT sql statement mysql_insert_id() returns 0;
pawn Код:
format(motd, sizeof(motd), "INSERT INTO `cocars` (`vModel`, `vUsage`, `vRespawnDelay`, `vOwner`, `vSpawned`) VALUES ('%d', '%d', '-1', '%s', '1')",
GetPVarInt(playerid, "SelectedForBuy")+400,
CAR_USAGE_PRIVATE,
playername);
mysql_query(motd, INSERT_VEHICLE_QUERY);
printf("MySQL Report: mysql_insert_id is %d.", mysql_insert_id());
I don't see any mistake here, if there is please help...
Thanks in advance.
Re: mysql_insert_id return 0 -
JaTochNietDan - 06.06.2012
Try using mysql_store_result beforehand, it's all I can think of as the code looks fine and it does make sense. So for example:
pawn Код:
format(motd, sizeof(motd), "INSERT INTO `cocars` (`vModel`, `vUsage`, `vRespawnDelay`, `vOwner`, `vSpawned`) VALUES ('%d', '%d', '-1', '%s', '1')",
GetPVarInt(playerid, "SelectedForBuy")+400,
CAR_USAGE_PRIVATE,
playername);
mysql_query(motd, INSERT_VEHICLE_QUERY);
mysql_store_result();
printf("MySQL Report: mysql_insert_id is %d.", mysql_insert_id());
mysql_free_result(); // Don't forget to free it then.
Re: mysql_insert_id return 0 -
CoaPsyFactor - 06.06.2012
It's not working, but thanks anyway
Re: mysql_insert_id return 0 -
JaTochNietDan - 06.06.2012
Quote:
Originally Posted by CoaPsyFactor
It's not working, but thanks anyway ![Cry](images/smilies/cry.gif)
|
I assume you have an auto incrementing column in your table? That's the value that it's supposed to get.
To confirm this can you please show us the table structure?
Re: mysql_insert_id return 0 -
CoaPsyFactor - 06.06.2012
It is AI, and key primary, that's the reason I'm asking here
Код:
CREATE TABLE IF NOT EXISTS `cocars` (
`vID` int(12) NOT NULL AUTO_INCREMENT,
`vModel` smallint(4) NOT NULL,
`vType` smallint(3) NOT NULL DEFAULT '0',
`vUsage` smallint(3) NOT NULL DEFAULT '0',
`vUsedFor` smallint(3) NOT NULL DEFAULT '0',
`vLocX` float NOT NULL DEFAULT '0',
`vLocY` float NOT NULL DEFAULT '0',
`vLocZ` float NOT NULL DEFAULT '0',
`vAngle` float NOT NULL DEFAULT '0',
`vColor1` smallint(3) NOT NULL DEFAULT '0',
`vColor2` smallint(3) NOT NULL DEFAULT '0',
`vRespawnDelay` int(12) NOT NULL DEFAULT '0',
`vFaction` smallint(3) NOT NULL DEFAULT '0',
`vJob` smallint(3) NOT NULL DEFAULT '0',
`vLocked` tinyint(1) NOT NULL DEFAULT '0',
`vInt` smallint(3) NOT NULL DEFAULT '0',
`vViwo` smallint(3) NOT NULL DEFAULT '0',
`vOwner` varchar(24) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL DEFAULT 'No-one',
`vSpawned` tinyint(1) NOT NULL DEFAULT '0',
`vehHealth` float NOT NULL DEFAULT '0',
`vPanels` int(12) NOT NULL DEFAULT '0',
`vDoors` int(12) NOT NULL DEFAULT '0',
`vehLights` int(12) NOT NULL DEFAULT '0',
`vTires` int(12) NOT NULL DEFAULT '0',
`vLock` tinyint(1) NOT NULL DEFAULT '0',
`vAlarm` tinyint(1) NOT NULL DEFAULT '0',
`vImobilizator` tinyint(1) NOT NULL DEFAULT '0',
`vFuel` smallint(3) NOT NULL DEFAULT '0',
`vSecurity` tinyint(1) NOT NULL DEFAULT '0',
`vTuned` tinyint(1) NOT NULL DEFAULT '0',
`vNeon` int(5) NOT NULL DEFAULT '0',
`vNumberPlate` int(8) NOT NULL DEFAULT '0',
`vPaintJob` tinyint(1) NOT NULL DEFAULT '0',
`vSpoiler` smallint(5) NOT NULL DEFAULT '0',
`vHood` smallint(5) NOT NULL DEFAULT '0',
`vRoof` smallint(5) NOT NULL DEFAULT '0',
`vSkirt` smallint(5) NOT NULL DEFAULT '0',
`vLamps` smallint(5) NOT NULL DEFAULT '0',
`vNitro` smallint(5) NOT NULL DEFAULT '0',
`vExhaust` smallint(5) NOT NULL DEFAULT '0',
`vWheels` smallint(5) NOT NULL DEFAULT '0',
`vStereo` smallint(5) NOT NULL DEFAULT '0',
`vHydraulics` smallint(5) NOT NULL DEFAULT '0',
`vFrontBumper` smallint(5) NOT NULL DEFAULT '0',
`vRearBumper` smallint(5) NOT NULL DEFAULT '0',
`vVentRight` smallint(5) NOT NULL DEFAULT '0',
`vVentLeft` smallint(5) NOT NULL DEFAULT '0',
`vTimesDestroy` smallint(2) NOT NULL DEFAULT '0',
`vGPS` tinyint(1) NOT NULL DEFAULT '0',
`vMelee` smallint(2) NOT NULL DEFAULT '0',
`vWeap1` smallint(2) NOT NULL DEFAULT '0',
`vWeap2` smallint(2) NOT NULL DEFAULT '0',
`vAmmo1` smallint(5) NOT NULL DEFAULT '0',
`vAmmo2` smallint(5) NOT NULL DEFAULT '0',
`vDrug1` smallint(5) NOT NULL DEFAULT '0',
`vDrug2` smallint(5) NOT NULL DEFAULT '0',
`vDrug3` smallint(5) NOT NULL DEFAULT '0',
`vDrug4` smallint(5) NOT NULL DEFAULT '0',
`vDrug5` smallint(5) NOT NULL DEFAULT '0',
`vDrugCode1` mediumint(6) NOT NULL DEFAULT '0',
`vDrugCode2` mediumint(6) NOT NULL DEFAULT '0',
`vDrugCode3` mediumint(6) NOT NULL DEFAULT '0',
`vDrugCode4` mediumint(6) NOT NULL DEFAULT '0',
`vDrugCode5` mediumint(6) NOT NULL DEFAULT '0',
`vTokiVoki` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`vID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=34 ;
I found some strange error, as you can see in structure default AUTO_INCREMENT is 34, and when I buy car id start from 1 :/
here is vID not Primary but I changed it in pma