AsyncMysqlConnection::host

Description

public function host(): string

The hostname associated with the current connection.

Return Values

  • string - The hostname as a string.

Examples

The following example shows how to get the host of the MySQL server that this connection is associated with via AsyncMysqlConnection::host.

<?hh

namespace Hack\UserDocumentation\API\Examples\AsyncMysql\Conn\Host;

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 get_host(): Awaitable<string> {
  $pool = new \AsyncMysqlConnectionPool(array());
  $conn = await connect($pool);
  $info = $conn->host();
  $conn->close();
  return $info;
}

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

run();
Output
string(9) "localhost"