Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.8Mb
PDF (A4) - 37.8Mb
PDF (RPM) - 36.4Mb
HTML Download (TGZ) - 9.8Mb
HTML Download (Zip) - 9.9Mb
HTML Download (RPM) - 8.6Mb
Man Pages (TGZ) - 209.5Kb
Man Pages (Zip) - 318.7Kb
Info (Gzip) - 3.5Mb
Info (Zip) - 3.5Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  /  ...  /  mysql_warning_count() mysql_warning_count()

unsigned int mysql_warning_count(MYSQL *mysql)


Returns the number of errors, warnings, and notes generated during execution of the previous SQL statement.

Return Values

The warning count.



User Comments
  Posted by Ding on November 16, 2005
Here is how we can use this function.

But we cant do anything else beside knowing that there warnings.

Here is a code in detecting errors and warnings in C.
My target here is to display error and warning count based on the query given in the variable.

You can just replace the value of szSqlStmt string to any querry you would like. Well we need to trap the error & warnings so just made it wrong.

//C language code

void main(){
char szSqlStmt[] = "DROP TABLE IF EXISTS no_such_table";
MYSQL *conn = mysql_init(NULL);
MYSQL_RES *res_set;


if (strlen(mysql_error(conn))) {//using strlen
fprintf (stderr,"%s",mysql_error(conn));
res_set = mysql_store_result(conn);

display the query info
fprintf(stdout,"\nQry nfo:%s",(char*)mysql_info(conn));

if (mysql_errno(conn)) {
Display the error message if any
fprintf (stderr,"\nError: %s",mysql_error(conn));

Display the Warning message if Any -- well in this case we have generated a warning...
if (mysql_warning_count(conn)) {
fprintf (stdout,"\nTHERE ARE '%d' WARNING FOUND!",mysql_warning_count(conn));
When it comes here we already know that there are warning.
It should be better if we have mysql_warning() to display the warning message.



Qry nfo:(null)
  Posted by Martin von Gagern on October 2, 2009
To get at the actual warning messages, the SHOW WARNINGS command can be used. See section of this manual.
Sign Up Login You must be logged in to post a comment.