AsyncMysqlException::mysqlErrorString
Returns a human-readable string for the error encountered in the current exception
public function mysqlErrorString(): string;
Returns
string
- The error string.
Examples
The following example shows how to use AsyncMysqlException::mysqlErrorString
to get the raw MySQL error string associated with this exception. For this example, the most likely exception string will be something like:
Access denied for user 'testuser'@'localhost' (using password: YES)
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,
"thisIsNotThePassword",
);
}
async function simple_query(): Awaitable<?string> {
$pool = new \AsyncMysqlConnectionPool(darray[]);
$conn = null;
$ret = null;
try {
$conn = await connect($pool);
$result = await $conn->query(
'SELECT name FROM test_table WHERE userID = 1',
);
$conn->close();
return $result->vectorRows()[0][0];
} catch (\AsyncMysqlConnectException $ex) { // implicitly constructed
$ret = "Connection Exception";
\var_dump($ex->mysqlErrorString());
} catch (\AsyncMysqlQueryException $ex) { // implicitly constructed
$ret = "Query Exception";
} catch (\AsyncMysqlException $ex) {
$ret = null;
} finally {
if ($conn) {
$conn->close();
}
}
return $ret;
}
<<__EntryPoint>>
async function run(): Awaitable<void> {
$r = await simple_query();
\var_dump($r);
}
```.hhvm.expectf
string(%d) "%s"
string(20) "Connection Exception"
```.example.hhvm.out
string(67) "Access denied for user 'testuser'@'localhost' (using password: YES)"
string(20) "Connection Exception"
```.skipif
await \Hack\UserDocumentation\API\Examples\AsyncMysql\skipif_async();