Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
void CMfc2Dlg::OnButton1() 
{
	// TODO: Add your control notification handler code here

				unsigned short Port = 3306;
				char *IPAddress = "localhost";
				char *UserName = "admin";
				char *Password = "BroadGate";
				char *DBName =  "bedrock";

				MYSQL *ssock;
				MYSQL_RES   *result;
				MYSQL_ROW   row;
				//char execsql[500];
				ssock = (MYSQL *)malloc(sizeof(MYSQL));
				mysql_init(ssock);
				if(ssock == NULL)
				{
					MessageBox("EROR: MySQL ssock init error. \n");
				}
				ssock = mysql_real_connect(ssock, IPAddress, UserName, Password, NULL, Port, NULL, 0);
				if(!ssock)
				{
					MessageBox("conn fail... \n");
					mysql_errno(ssock);
				}
				else
				{
							cout<<" MySql Connected\n";
							mysql_query(ssock, "call testproc");
  
						  result = mysql_store_result(ssock);
						  num_fields = mysql_num_fields(result);
						  while ((row = mysql_fetch_row(result)))
						  {
							  for(i = 0; i < num_fields; i+=1)
							  {
								  cout<< row[i] << endl;
								  cout<<"\n";
							  }
							  
						  }

						  mysql_free_result(result);
						  mysql_close(conn);
						    system("pause");
							return;
				}

				if(mysql_select_db(ssock, DBName) != 0)
				{
					MessageBox("select db error. \n");
				}
	
}
Posted
Updated 13-Jan-15 22:42pm
v2
Comments
Kornfeld Eliyahu Peter 14-Jan-15 4:42am    
Instead of posting a new question you better update the existing one - or at least remove it!
Sinisa Hajnal 14-Jan-15 4:48am    
You lack some include file which defines MYSQL struct / class.
OriginalGriff 14-Jan-15 5:02am    
Don't repost the same question: Use the "Improve question" widget to edit your question and provide better information instead.

I have deleted the older "spare".

1 solution

You're missing an include. Specifically,

C++
#include <mysql.h>
 
Share this answer
 
v2
Comments
CPallini 14-Jan-15 15:45pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900