You can call the mysql_error() function to return a null-terminated string that contains the error message for the most recently called API function that failed.
Syntax
const char *
mysql_error(MYSQL *mysql)
Return values
For the connection specified by mysql, if the function did not fail, the return value of mysql_error() may be the previous error or an empty string to indicate no error.
Errors
None.
Notes
For the connection specified by mysql, mysql_error() returns a null-terminated string that contains the error message for the most recently called API function that failed. If the function did not fail, the return value of mysql_error() may be the previous error or an empty string to indicate no error.
As a rule, all functions that ask the server for information will reset mysql_errno() if they succeed.
For functions that reset mysql_error(), either of the following two tests can be used to check for an error:
if(*mysql_error(&mysql))
{
// An error occurred.
}
if(mysql_error(&mysql)[0])
{
// An error occurred.
}