AsyncMysqlRowBlock::isEmpty

Description

public function isEmpty(): bool

Returns whether there were any rows are returned in the current row block.

Return Values

  • bool - true if there are rows; false otherwise.

Examples

The following example uses AsyncMysqlRowBlock::isEmpty to determine whether there are actually any row_blocks returned from the call to AsyncMysqlRowBlock::rowBlocks() method

<?hh

namespace Hack\UserDocumentation\API\Examples\AsyncMysql\RowBlock\IsEmpty;

use \Hack\UserDocumentation\API\Examples\AsyncMysql\ConnectionInfo as CI;

async function connect(\AsyncMysqlConnectionPool $pool):
  Awaitable<\AsyncMysqlConnection> {
  return await $pool->connect(
    CI::$host,
    CI::$port,
    CI::$db,
    CI::$user,
    CI::$passwd
  );
}
async function simple_query(): Awaitable<int> {
  $pool = new \AsyncMysqlConnectionPool(array());
  $conn = await connect($pool);
  $result = await $conn->query(
    'SELECT * FROM test_table WHERE userID < 50'
  );
  $conn->close();
  // A call to $result->rowBlocks() actually pops the first element of the
  // row block Vector. So the call actually mutates the Vector.
  $row_blocks = $result->rowBlocks();
  if (!$row_blocks->isEmpty()) {
    // An AsyncMysqlRowBlock
    $row_block = $row_blocks[0];
    return $row_block->count(); // int
  } else {
    return -1;
  }
}

function run(): void {
  $r = \HH\Asio\join(simple_query());
  var_dump($r);
}

run();
Output
int(2)