MySQL provides APIs in many languages, including C, C ++, PHP, Perl, and python. C API is used in this program, and the code is universal. The Code is as follows:
MySQL;
Mysql_res * mysql_result;
Mysql_row;
Char TMP [64];
Wxstring STR;
If (mysql_init (& MySQL) = NULL)
{
Wxmessagedialog DLG (this, _ ("unable to initialize MySQL struct! "));
DLG. showmodal ();
}
If (mysql_real_connect (& MySQL, "202.117.10.254", "xjtugrid", "xjtugrid", "grid_context_monitor", 3306, null, 0) = NULL)
{
Wxmessagedialog DLG (this, _ ("unable to connect MySQL! "));
DLG. showmodal ();
Return;
}
If (mysql_query (& MySQL, "select * from user ")! = 0)
{
Wxmessagedialog DLG (this, _ ("unable to query MySQL! "));
DLG. showmodal ();
Return;
}
Mysql_result = mysql_store_result (& MySQL );
If (mysql_result = NULL)
{
Wxmessagedialog DLG (this, _ ("unable to query MySQL! "));
DLG. showmodal ();
Return;
}
While (mysql_row = mysql_fetch_row (mysql_result ))
{
Sprintf (TMP, "% s", mysql_row [0]);
Wxstring wx_string (TMP, wxconvutf8 );
STR + = wx_string;
}
Wxmessagedialog DLG (this, STR );
DLG. showmodal ();