You will find mysql.h file here:
http://www.distlab.dk/mysq
Main Topics
Browse All TopicsTrying 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/mys
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
// 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/downl
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.source
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You will find mysql.h file here:
http://www.distlab.dk/mysq
Also consider that you will need libmySQL.lib or libmySQL.dll available at www.mysql.com
Axter, I am aware of the possibility (and even have a book with a chapter on how to do that), but I need the program to be self-contained.
The target user for the app I'm building is not at all computer savvy and the simplest the installation/operation, the better.
jaime_olivares, the mysql.h you link to is the same one I have (that came in the mysql source code), so I'm still in the same place.
Can you tell me more about the libmySQL.* you are talking about? How do I install those?
(by the way, thanks for the lighning fast replies)
jkr, I think you are onto something.
My code now looks like this:
// mysql test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <winsock.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
// 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 I'm still getting these errors:
mysql test.obj : error LNK2001: unresolved external symbol _mysql_close@4
mysql test.obj : error LNK2001: unresolved external symbol _mysql_query@8
mysql test.obj : error LNK2001: unresolved external symbol _mysql_real_connect@32
mysql test.obj : error LNK2001: unresolved external symbol _mysql_init@4
Debug/mysql test.exe : fatal error LNK1120: 4 unresolved externals
>But I'm still getting these errors:
>mysql test.obj : error LNK2001: unresolved external symbol _mysql_close@4
>mysql test.obj : error LNK2001: unresolved external symbol _mysql_query@8
This is because you don't have the proper .lib file, where actual functions are located.
The .h file is just a header to declare those functions.
jaime, you are right. I compiled libmysql.lib and linked it to my project and most of the errors went away.
I knew it had to do with libmysql.lib because you mentioned it earlier. Is there any way to know what lib is missing?
My only error now is:
======================
Linking...
LIBCD.LIB(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/mysql test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
mysql test.exe - 2 error(s), 0 warning(s)
======================
I'm assumming it has to do with LIBCD.LIB, but this file came with the VC++ 6 standard install. It doesn't matter if I link it to my project or not, it will still return the same error...
Since you have answered my question and these compilation errors have nothing to do with the original question, I will assign points to the corresponding answers.
I'm just going to ask you to help me to figure this small compilation error before you leave :)
Hi poisa, thanks for the points.
About the WinMain problem, that will depend on what kind of application (windows,console) you are trying to generate, it is not related with mysql at all.
Read this article from Microsoft:
http://support.microsoft.c
Also have a look to these previous questions discussing this problem:
http://www.experts-exchang
http://www.experts-exchang
Business Accounts
Answer for Membership
by: AxterPosted on 2005-02-09 at 08:57:17ID: 13266118
Hi poisa,
I recommend that you use ODBC to connect to MySQL.
That would make your code more portable to another type of database, if you decide to change it.
Cheers!