Solved

mySQL with C++

Posted on 2001-07-02
9
374 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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++.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now