在wxwidgets程序中访问mysql(二)--代码
时间:2009-07-01 来源:llqkk
MYSQL mysql;
MYSQL_RES *mysql_result;
MYSQL_ROW 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();