Advertisement

02.09.2005 at 08:37AM PST, ID: 21308091
[x]
Attachment Details

Trying to connect to MySQL from Visual C++ 6 (Windows MFC Application)

Asked by poisa in Windows MFC Programming

Tags: , ,

Trying to connect to MySQL from Visual C++ 6 (Windows MFC Application)

Hi,

I'm trying to connect to a MySQL database from C++. First I downloaded mysql++-1.7.28.tar.gz from here --> http://tangentsoft.net/mysql++/. I then copied this to some folder and added it to the Visual C++ inlcude directories

After browsing through the forums, I found this code:


#include "stdafx.h"
#include <mysql.h>


int main()
{

// create a pointer of the type mysql
MYSQL *conn;
// initialize your mysql connection
conn = mysql_init(NULL);
// connect to your database
mysql_real_connect(conn,"localhost","username","password","database",0,NULL,0);
// perform a query
mysql_query(conn,"UPDATE my_table SET somevalue = somevalue + 1 WHERE id = 5");
// close the connection
mysql_close(conn);

 return 0;
}

But it seems that I don't have the mysql.h file, as this returns "fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory"

I then downloaded the MySQL Windows source files from here --> http://dev.mysql.com/downloads/mysql/4.1.html and found the necessary file inside. I copied this file to the include dir and asks for two other files: mysql_com.h, and mysql_version.h, which I proceed to copy also to the specified dir. After this, I compile again and get:

error C2146: syntax error : missing ';' before identifier 'fd'
error C2501: 'SOCKET' : missing storage-class or type specifiers
error C2501: 'fd' : missing storage-class or type specifiers

Can anyone give me some pointers on this one?

Bare in mind that I'm starting out with C++ and don't fully understand the terminology, so try to keep it simple.
My main objective is to create an MFC Application, but I figure that if I can get a Win32 Console App to connect to the db, then the rest is downhill.

Thanks.

PS: I also tried this other API (http://mysqlcppapi.sourceforge.net/) without any success.Start Free Trial
 
Keywords: Trying to connect to MySQL from Visu…
 
Loading Advertisement...
 
[+][-]02.09.2005 at 08:57AM PST, ID: 13266118

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.09.2005 at 09:00AM PST, ID: 13266154

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.09.2005 at 09:04AM PST, ID: 13266204

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.09.2005 at 09:08AM PST, ID: 13266253

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.09.2005 at 09:19AM PST, ID: 13266388

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.09.2005 at 09:33AM PST, ID: 13266558

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.09.2005 at 10:03AM PST, ID: 13266906

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Windows MFC Programming
Tags: mysql, connect, visual
Sign Up Now!
Solution Provided By: jaime_olivares
Participating Experts: 3
Solution Grade: A
 
 
[+][-]02.09.2005 at 10:04AM PST, ID: 13266918

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.09.2005 at 11:59AM PST, ID: 13268397

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.09.2005 at 12:23PM PST, ID: 13268685

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.09.2005 at 12:32PM PST, ID: 13268784

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32