in my queries Code: -- # {reduce_money -- # :username string -- # :money int UPDATE economy SET money = money - :money WHERE player = :username; -- # } the method PHP: public static function reduceMoney(Player $player, int $amount) { $plugin = MainClass::getInstance(); $plugin->provider->executeChange("reduce_money", [ "username" => $player->getName(), "money" => $amount ]); } when i reduce money(my current money is 80,000,000btw) PHP: EconomyAPI::reduceMoney($player, 60000000); it gives me -60000000 in the database
Because he wants to deduct the value he sends to that function from the current value in his db - doesn't he have to select the value first?
Move this to facepalm. You reduce the money, you take them, you get them away. Maybe addMoney or EconomyAPI::reduceMoney($player, -60000000); or setMoney($player, $currentMoney - 60000000)
It sounds pretty obvious, PHP: $money = 0;function reduceMoney(int $reduce){ $money = $money - $reduce;}reduceMoney(6000000);//0 - 6000000? -6000000 You could use SQLite3's MAX() function to cap the value you're setting. Code: UPDATE table SET value=MAX(0, value - value - 1); //value = 0
Looks to me like we are all assuming different things are happening in the code that the OP didn't post. Yet again, please post links to your plugin on github, or complete code.
He's writing "money = money - :money" in his DB. The first and second "money"s are column name references, and ":money" is a variable. Why does he need to select the value first if it can be represented in the query already? If his original amount of money is indeed 80,000,000 and he subtracted 60,000,000, he is indeed doing the right thing. But I think it's more likely that he made some mistakes in testing, e.g. his original amount of money was 0 not 80,000,000.
Indeed... according to https://sqlite.org/lang_update.html: So you've messed up elsewhere, and we can't know where from the information you posted.