can any body give me a sample program and description about "how to connect c++ with mysql in linux platform" and i need what are the headler file it supports
Printable View
can any body give me a sample program and description about "how to connect c++ with mysql in linux platform" and i need what are the headler file it supports
Are you wanting native MySQL connectivity or are you looking for
ODBC compliance? If you want native MySQL connectivity, they
have MySQL Connector++. If you want ODBC connectivity [so
that you don't need to rely upon the database being MySQL],
then you'll need an ODBC driver manager. You can get unixODBC
at http://www.unixodbc.org
or iODBC [I don't have the link for iODBC]. You then need the
sql client itself. For this, I usually download MySQL and install/use
only the libmysqlclient portion. Despite its name, it's only a bunch
of MySQL function. At this point, you can use the SQL*() functions
to connect to the SQL database ... but what about C++, you ask?
Well, there are many solutions. My favorite would probably be
the DTL. You can also look up OTL [and probably others], but I
don't have a link for that. Here's an example DTL program and
I'll leave the rest as an exercise for you:
--PaulCode:#include "util/exception/BaseException.h"
#include <DTL.H>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace dtl;
using namespace std;
using namespace util;
int main(int argc, char* argv[])
{
try
{
DBConnection::GetDefaultConnection().Connect("UID=ecDocUser;DSN=ecDoc;");
DynamicDBView<> view("docmanagerhistory", "*");
// print out the column names
vector<string> columnNames = view.GetDataObj().GetNames();
copy(columnNames.begin(), columnNames.end(), ostream_iterator<string>(cout, " "));
cout << endl;
// now print out the returned data
copy(view.begin(), view.end(), ostream_iterator<variant_row>(cout, "\n"));
}
catch (std::exception& ex)
{
cerr << BaseException::createCatchDetail(ex, "main()") << endl;
return 1;
}
return 0;
}