CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Location
    mysore, india
    Posts
    21

    Angry how to connect c++ with mysql in linux platform

    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
    j.sakthivel

  2. #2
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    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:
    Code:
    #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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured