I would like to know if the result of QueryResult is efficient and use well because I just used this lib and I don't know it too well and I would like to know if I respected the code by defining the resultRows response with $data in the callable and then returning it in the function. I would like to know if I have respected the priorities and if you have any ideas for code optimization or anything else.
regards, Nicolas.
public function getAllDataFrom(string $table)
{
$name = strtolower($this->getName());
$data = null;
$loop = \React\EventLoop\Factory::create();
$connection = new \React\MySQL\Factory($loop);
$my = $connection->createLazyConnection(Utils::USER . ':' . Utils::PASSWORD . '@' . Utils::HOST . ':3306/' . Utils::BASE);
$my->query("SELECT * FROM $table WHERE name='" . $name . "'")->then(static function(QueryResult $queryResult) use ($my, &$data) {
$my->quit();
$data = $queryResult->resultRows;
return $queryResult->resultRows;
});
$loop->run();
return $data[0] ?? [];
}