fair warning, it probably won't work, but try this: PHP: $escapedName = mysqli::real_escape_string($sender->getName());/** @var mysqli_result|bool $result **/$result = $this->plugin->provider->db->query("SELECT * FROM rede_geral WHERE lang = 'en' AND nome='{$escapedName}';");if($result !== false) { $sender->sendMessage("Hello"); return true;}/** @var mysqli_result|bool $result **/$result = $this->plugin->provider->db->query("SELECT * FROM rede_geral WHERE lang = 'pt' AND nome='{$escapedName}';");if($result !== false) { $sender->sendMessage("Olá"); return true;}return true;
I don't know why but when i test the command it only say's "Hello", even being the database of the player in lang are 'pt'
A SELECT query without a syntax error always returns a mysqli_result. You have to fetch a row to find out the called, e.g.: PHP: $result = $mysqli->query("SELECT COUNT(*) AS cnt FROM rede_geral WHERE lang = 'pt' AND name = '{$mysqli->escape_string($username)}'");$row = $result->fetch_assoc();$result->close();$exists = $row["cnt"] > 0; Nevertheless, you should always minimize the number of queries you send. So your whole code in the OP can be changed to a single SELECT statement: PHP: SELECT lang FROM rede_geral where nome = 'escaped name here' Then check the result using PHP.
I don't have understand so much this code, but when i test it says that 20.10 22:49:53 20.10 22:50:06 [Server] Server thread/CRITICAL Unhandled exception executing command 'lang' in lang: Undefined variable: lang PHP: 20.10 22:49:53 20.10 22:50:06 [Server] Server thread/CRITICAL Unhandled exception executing command 'lang' in lang: Undefined variable: lang$result = $$this->plugin->provider->db->query("SELECT COUNT(*) AS cnt FROM rede_geral WHERE lang = 'en' AND nome = '{$this->plugin->provider->db->query->escape_string($sender)}'"); Like, i really just want to have a function like "if player has lang = "en" then sendmessage("Hello!") but in database" Like this code in YML: PHP: $playerlang = new Config($this->getDataFolder() . "/languages.yml", Config::YAML); $lang = new Config($this->getDataFolder() . "/lang.yml", Config::YAML); //Get database $msg = $lang->get($playerlang->get($pl->getName())); //Get player lang on database $pl->sendMessage($msg["hi_message"]);
MySQLi is only used to execute queries and return values in rows. When you execute a SELECT query, it sends a request to the MySQL server, then waits for the response. The response from the MySQL server is called a "result set", which contains data in rows. For this query: Code: SELECT COUNT(*) AS cnt FROM rede_geral WHERE lang = 'en' AND nome = '$name' The MySQL server will return a result set with one row, with one column `cnt`. So the only column in the only row contains an integer, showing how many matches there are for "rede_geral WHERE lang='en' AND nome='$name'". However, you should optimize your queries. Here, you just want to know the lang of the player. You can download the player's lang into a variable, then compare the variable in PHP offline. In other words: PHP: $result = $mysqli->query("SELECT lang FROM rede_geral WHERE nome = '{$mysqli->escape_string($player->getName())}'");$row = $result->fetch_assoc();$result->close(); // close the mysqli_result if it is no longer used.if(is_array($row)){ // there is a row in rede_geral for this player $lang = $row["lang"]; if($lang === "en"){ // send message in English }elseif($lang === "pt"){ // send message in Portuguese }}else{ // rede_geral does not have any information for this player. What do you do now?}