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,"l
ocalhost",
"username"
,"password
","databas
e",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