仅从错误代码获取MySQL错误消息

What's the point of MySQL error Codes (like 1054)?

The error messages contain the actual information, so there must be some way of getting some more information out of the error codes.

But what can I use to get anything from the error code alone compared to the error message?

Normally you get both with :

<?PHP
$db_link = new mysqli($hostname, $username, $password, $database);

$statement = $db_link->prepare('SELECT SomeFieldThatDoesNotExist FROM Person');
$statement->execute();

if(!$statement) {
    $specific_error = $db_link->error;
    $error_number = $db_link->errno;
}
?>

Imagine that I have error 1054 (see: https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html#error_er_bad_field_error).

With just the number 1054, what can I use to get the actual MySQL error message itself?

Use the MySQL Error Codes PHP lib on Github: https://github.com/HoldOffHunger/mysql-errors-codes .

Normal error messaging style :

$db_link = new mysqli($this->hostname,$this->username,$this->password);
print($db_link->connect_errno . " : " . $db_link->connect_error);

Normal error messaging output :

13236 : Message: Newly created data directory SOMEDIRECTORY is unusable. You can safely remove it.

New, fuller error-messaging style :

$mysql_error = new MySQLErrorCode();
$error_codes = $mysql_error->ErrorCodes();

print_r($error_codes[13236]);

Output :

13236 : Message: Newly created data directory SOMEDIRECTORY is unusable. You can safely remove it.

'13236' => [
    'error_code' => '13236',
    'internal_code' => 'ER_DATA_DIRECTORY_UNUSABLE',
    'message_template' => 'Message: Newly created data directory %s is unusable. You can safely remove it.',
    'sql_state' => 'HY000',
    'version_information' => 'ER_DATA_DIRECTORY_UNUSABLE was added in 8.0.13.'
],

use SHOW ERRORS;

Manual : https://mariadb.com/kb/en/mariadb/show-errors/

SELECT f();
ERROR 1305 (42000): FUNCTION f does not exist

SHOW COUNT(*) ERRORS;
+-----------------------+
| @@session.error_count |
+-----------------------+
|                     1 |
+-----------------------+

SHOW ERRORS;
+-------+------+---------------------------+
| Level | Code | Message                   |
+-------+------+---------------------------+
| Error | 1305 | FUNCTION f does not exist |
+-------+------+---------------------------+