j_sakthivel
April 4th, 2003, 01:38 AM
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
|
Click to See Complete Forum and Search --> : how to connect c++ with mysql in linux platform j_sakthivel April 4th, 2003, 01:38 AM 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 PaulWendt April 4th, 2003, 06:17 AM Are you wanting native MySQL connectivity or are you looking for ODBC compliance? If you want native MySQL connectivity, they have MySQL Connector++ (http://www.mysql.com/products/mysql++/index.html). 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 (http://dtemplatelib.sourceforge.net/index.htm). 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: #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; } --Paul codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |