CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2001
    Location
    israel
    Posts
    112

    c++ in collaboration with mysql

    Does any one know how to contact a mysql server through a c++ application ?
    I'd like to run a code such as:
    Code:
    int main()
    // this is a mysql command
    use MyDb;
    for(int i=0; i++; i<10)
    // The following is a mysql command
    INSERT INTO MyTable(Counter)
    VALUES(i);
    retrun (0);
    can anyone guide me how to write the mysql commands using c++ code ?
    Thanks/

  2. #2
    Join Date
    Mar 2004
    Location
    Temuco, CHILE
    Posts
    161

    Re: c++ in collaboration with mysql

    There is a library called mysql++, which implements the functionality you're asking. It can even work your queries as if they were iostreams:

    Code:
    mysqlstream myquery;
    myquery << "SELECT * FROM TABLE1"<< endl;
    myquery.parse(); // executes the query and restores info in a "Record" object or something like that
    Results are obtained in a special kind of object from which you can select the row as an array index, and the attribute as a map index:
    Code:
    mysqlresult myresult= myquery.result();
    Row e1= result[1];
    cout<< "First person's age: "<< e1["age"]<< endl;
    At least, I think it works thus way.

    The problem is, the current version is very C++-inflexible and thus won't work with compilers such as VC++ 6.0 which "poorly implements C++" (according to the author's website). You will need to either
    a) DL another compiler (DevC++ for example)
    b) use a newer version of Visual C++ (maybe the 2003 Toolkit)
    c) DL an older version of mysql++, which is not guaranteed to work all the way you could expect.

    Anyway I suggest you to try, I am doing that too!


    I don't know the website, but you should Google it with the "lucky" button and you should get there immediately.
    You're not watching "24"?
    Well... you should.

    24
    Jack IS back...

  3. #3
    Join Date
    May 2001
    Location
    israel
    Posts
    112

    Thanks a lot !

    I'll try it.

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