Using libasynql Code PHP: /** * @param callable $callable * @param Player $player * @return float */ public function getMoney(Player $player, callable $callable) { if (!$player instanceof Player) { return true; } $uuid = $player->getUniqueId(); $result = $this->connector->executeSelect(Queries::GET_BALANCE, [ "uuid" => (string) $uuid ], $callable); return $result; } mysq.sql PHP: -- # {get-- # {balance-- # :uuid stringSELECT BALANCE FROM players WHERE UUID=:uuid;-- # }-- # } and when i call it PHP: $this->getPlugin()->getProvider()->getMoney( $sender, function (array $rows) use ($sender, $uuid) { $sender->sendMessage("balance - ".$rows[0]["BALANCE"]); }); gives [19:15:57] [Server thread/CRITICAL]: ErrorException: "Undefined offset: 0" by the (EXCEPTION)
Seems like normal behaviour. If $rows is empty then the player's record doesn't exist in the "players" table.
Ah, I see. So this is where the issue is: (string) $uuid converts the UUID to those readable text uuids that contain hyphens. Since you store them in binary, you need to PHP: "uuid" => $uuid->toBinary() P.S. The reverse of UUID->toBinary() is UUID::fromBinary(). Also, $player->getRawUniqueId() is a shorthand for $player->getUniqueId()->toBinary().
Will it make any difference if i make the uuid column varchar instead of binary and save uuid as string ?
You could store UUIDS as CHAR(36) yeah. You'll need to change your UUID implementation back to (string) $uuid for this. Binary strings I could say have at least two benefits: They take lesser storage space and are definitely faster to look up. Though I'm not sure if the performance impact by storing UUIDs as CHAR is that significant. PMMP has a method to fetch a player directly (O(1)) by their binary UUID - Server::getPlayerByRawUUID($uuid). There is a method to fetch player by a UUID object as well but thats basically converting UUID object to binary and calling getPlayerByRawUUID. Yes, there's Server::geyPlayerExact($nams) as well but that in it's worst case is O(n) as it iterates over every online player (or at least attempts to). P.S. MySQL 8 has UUID_TO_BIN(binary UUID) and BIN_TO_UUID(string UUID) to convert between the two forms of UUID.
This is a bit different, but if i want to print out the player's skin on my website and on my pm server, what should be my skin data column be? Mediumblob(16)?