Solved

mySQL with C++

Posted on 2001-07-02
9
395 Views
Last Modified: 2008-03-06
Okay, I'm pretty new to C++ here, so y'all might have to speak in newbie terms or I'll get lost!

Basically, I want to start using C or C++ to access a mySQL database. I'll set up a little scenario for the purpose of this question...

I have a mySQL table set up with three fields, X, Y and Z. I want my C++ program to read in the three values, then multiply X by Y, and increment the value of Z by this figure.

I then want to update the database.

I tried to install the API available on mySQL.com but failed miserably, so I could do with a step-by-step guide for this too. I use the Borland C++ Compiler (5.5).

Thanks in advance,

Stephen Sherlock
0
Comment
Question by:stesherlock
9 Comments
 

Expert Comment

by:le
ID: 6248580
The simpliest way to do what you want is to use ODBC driver, which comes with mySQL. Install it. Then using ODBC32 tool from controll pannel. COnfigure it to point to proper mySQL database. I do not know too much about Borland 5.5 but it may have some odbc related classes build in. Also many freeware C++ ODBC wrappers are avaliable.
0
 

Author Comment

by:stesherlock
ID: 6252411
Okay, I can use ODBC (played with it before so I could access my mySQL DB via MS Access before I found a little program called mySQL-Front) but I'd need some help on using C++ to access the DB via ODBC...
0
 
LVL 1

Expert Comment

by:CSLIU
ID: 6254262
MSDN on-line help (ODBC):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcsqlconnect.asp

there are many ways.

1,database <-> ODBC <-> App.
2,database <-> ODBC <-> ADO(OLE DB) <-> App.
3,database <-> ODBC <-> DAO <-> App.
4,database <-> ODBC <-> BDE(Borland Database Engine) <-> App.



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:stesherlock
ID: 6257917
I've heard that ODBC is a little slow though, and my eventual project is going to need optimisation. Is it relatively easy to access mySQL directly from C++?
0
 

Expert Comment

by:sumansamanta
ID: 6258624
ODBC is quit good for accessing global data, but since its purpose is to access heterogenous database, it may not be as optimized as native data access APIs provided by particular Database vendors (like OCI for Oracle, DB Library for Sybase, DAO for MS Access). I don't know whether that kind of native API is available for MYSQL or not ?

   But I still think you should use ODBC as your database access tool, because it is most commonly used for windows platform and most well documented. You can seek help from MSDN or Microsoft's site (www.microsoft.com for MSDN online), in this issue. A well written program using ODBC is good enough in speed and is not that slow , as you are thinking. Plus you have the added advantage that, if in future you decide to change your backend (say from MYSQL to Oracle) then no changes or may be very little changes are required in your C/C++ code.

You can visit some sites like www.codeguru.com for sample codes.
0
 
LVL 1

Expert Comment

by:CSLIU
ID: 6260294
> I've heard that ODBC is a little slow though, and my
> eventual project is going to need optimisation.
> Is it relatively easy to access mySQL directly from C++?

yes.

http://www.mysql.com/downloads/api-mysql++.html

or

http://www.mysql.com/Downloads/mysql++/mysql++-1.7.1-win32-borland.zip

0
 
LVL 1

Accepted Solution

by:
CSLIU earned 200 total points
ID: 6260321
> I tried to install the API available on mySQL.com but
> failed miserably, so I could do with a step-by-step
> guide for this too. I use the Borland C++ Compiler (5.5).

what's the problem?
0
 
LVL 11

Expert Comment

by:griessh
ID: 6825264
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "CSLUI" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 

Author Comment

by:stesherlock
ID: 6829307
Sorry for forgetting about you peeps, very long sotry though...

I'll give the points to CSLIU, but I don't use C++ these days (don't have the time) so I never even got to try any of these solutions :(
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Embarcadero C++ Builder XE2 TDateTime 8 80
typedef std::deque<BYTE> ByteVector is broken in vs2012 23 89
FMX TCameraComponent Problem 2 92
max float value 3 59
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question