phpscriptcoder Posted February 12, 2009 Share Posted February 12, 2009 I'm trying to fix someone's game script. It has some code which inserts a new row into the database, and 3 of the fields can be very large (in the quadrillions). But when the row is inserted, the 3 large fields are set to 0. The field types are BIGINT unsigned with length 21. Before being inserted into the database, the number is added to a variable which is often 0, if that matters. Thanks for helping! Quote Link to comment Share on other sites More sharing options...
samshel Posted February 12, 2009 Share Posted February 12, 2009 could u post some code ? Quote Link to comment Share on other sites More sharing options...
corbin Posted February 12, 2009 Share Posted February 12, 2009 Considering bigints can go to about 10^19 and quadrillions are 10^15 through 10^16-1, it must be an error with code. Quote Link to comment Share on other sites More sharing options...
phpscriptcoder Posted February 12, 2009 Author Share Posted February 12, 2009 Here is some code. $Mining['metal'] = 0; $Mining['crystal'] = 0; $Mining['deuter'] = 0; ... if ($FleetStorage > 0) { $metal = $TargetPlanet['metal'] / 2; $crystal = $TargetPlanet['crystal'] / 2; $deuter = $TargetPlanet["deuterium"] / 2; if (($metal) > $FleetStorage / 3) { $Mining['metal'] = $FleetStorage / 3; $FleetStorage = $FleetStorage - $Mining['metal']; } else { $Mining['metal'] = $metal; $FleetStorage = $FleetStorage - $Mining['metal']; } if (($crystal) > $FleetStorage / 2) { $Mining['crystal'] = $FleetStorage / 2; $FleetStorage = $FleetStorage - $Mining['crystal']; } else { $Mining['crystal'] = $crystal; $FleetStorage = $FleetStorage - $Mining['crystal']; } if (($deuter) > $FleetStorage) { $Mining['deuter'] = $FleetStorage; $FleetStorage = $FleetStorage - $Mining['deuter']; } else { $Mining['deuter'] = $deuter; $FleetStorage = $FleetStorage - $Mining['deuter']; } } ... $Mining['metal'] = round($Mining['metal']); $Mining['crystal'] = round($Mining['crystal']); $Mining['deuter'] = round($Mining['deuter']); ... $Mining['metal'] = $Mining['metal'] + $FleetRow["fleet_resource_metal"]; $Mining['crystal'] = $Mining['crystal'] + $FleetRow["fleet_resource_crystal"]; $Mining['deuter'] = $Mining['deuter'] + $FleetRow["fleet_resource_deuterium"]; $QryUpdateFleet = "UPDATE {{table}} SET "; $QryUpdateFleet .= "`fleet_amount` = '". $FleetAmount ."', "; $QryUpdateFleet .= "`fleet_array` = '". $FleetArray ."', "; $QryUpdateFleet .= "`fleet_mess` = '1', "; $QryUpdateFleet .= "`fleet_resource_metal` = '". $Mining['metal'] ."', "; $QryUpdateFleet .= "`fleet_resource_crystal` = '". $Mining['crystal'] ."', "; $QryUpdateFleet .= "`fleet_resource_deuterium` = '". $Mining['deuter'] ."' "; $QryUpdateFleet .= "WHERE fleet_id = '". $FleetRow['fleet_id'] ."' "; $QryUpdateFleet .= "LIMIT 1 ;"; doquery( $QryUpdateFleet , 'fleets'); Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 12, 2009 Share Posted February 12, 2009 Add echo $QryUpdateFleet; before doquery( $QryUpdateFleet , 'fleets'); this will show if the problem is with how query is formed, or maybe it's in MySQL Quote Link to comment Share on other sites More sharing options...
phpscriptcoder Posted February 13, 2009 Author Share Posted February 13, 2009 UPDATE {{table}} SET `fleet_amount` = '290401619', `fleet_array` = '203,290401619;', `fleet_mess` = '1', `fleet_resource_metal` = '2.42001349167E+15', `fleet_resource_crystal` = '2.42001349167E+15', `fleet_resource_deuterium` = '2.42001349167E+15' WHERE fleet_id = '6772' LIMIT 1 ; I'm not sure if that's the problem, because it works for smaller numbers. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 13, 2009 Share Posted February 13, 2009 The problem is that you're quoting the numbers which makes them into strings. Putting a string into a numeric field will cause a zero to be entered. Remove the quotes. Ken Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 13, 2009 Share Posted February 13, 2009 The problem is that you're quoting the numbers which makes them into strings. Putting a string into a numeric field will cause a zero to be entered. Nope. Unless there is some SQL compatibility mode that enforces that. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 13, 2009 Share Posted February 13, 2009 Sorry, my mistake. Ken Quote Link to comment Share on other sites More sharing options...
samshel Posted February 13, 2009 Share Posted February 13, 2009 '2.42001349167E+15' is not recognized as integer by MySQL. Try to format the number properly. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 13, 2009 Share Posted February 13, 2009 Actually, it is. I just tried it via phpMyAdmin and it worked fine. Ken Quote Link to comment Share on other sites More sharing options...
phpscriptcoder Posted February 14, 2009 Author Share Posted February 14, 2009 PHP is changing the number to be formatted that way. Also, I noticed that sometimes the number is set to 2 or 3 or 4, not only 0. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.